Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: fix generics method call with struct short syntax args(fix #20030) #20100

Merged
merged 1 commit into from Dec 6, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Dec 6, 2023

  1. Fixed Unkown type error when inferring type from params struct with a generic embedded struct. #20030
  2. Add tests.
pub type Handler[T] = fn (mut T) bool

@[params]
pub struct Options[T] {
	handler fn (mut T) bool @[required]
}

struct Collector[T] {
mut:
	handlers []Handler[T]
}

pub fn (mut c Collector[T]) use(options Options[T]) {
	c.handlers << options.handler
}

pub struct Context {}

fn test_handler(mut ctx Context) bool {
	println('from test_handler!')
	return true
}

pub struct MainStruct {
	Collector[Context]
}

fn main() {
	mut s := MainStruct{}
	s.use(handler: test_handler)
	assert s.handlers.len == 1
}

outputs:

passed

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit 55e86fe into vlang:master Dec 6, 2023
54 checks passed
@shove70 shove70 deleted the patch-2 branch December 6, 2023 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unkown type error when inferring type from params struct with a generic embedded struct.
2 participants