Skip to content

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

Merged
spytheman merged 1 commit into
vlang:masterfrom
shove70:patch-2
Dec 6, 2023
Merged

spytheman merged 1 commit into
vlang:masterfrom
shove70:patch-2

Conversation

@shove70

@shove70 shove70 commented Dec 6, 2023

Copy link
Copy Markdown
Contributor
  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

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

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
@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