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 generic array method call with multi-types (fix #20230) #20237

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Dec 21, 2023

This PR fix generic array method call with multi-types (fix #20230).

  • Fix generic array method call with multi-types.
  • Add test.
pub type EventListener[T] = fn (T) !

pub type Check[T] = fn (T) bool

pub struct EventController[T] {
mut:
	id        int
	listeners map[int]EventListener[T]
}

fn (mut ec EventController[T]) generate_id() int {
	return ec.id++
}

@[params]
pub struct EmitOptions {
pub:
	error_handler ?fn (int, IError)
}

pub fn (mut ec EventController[T]) emit(e T, options EmitOptions) {
	if ec.listeners.len == 1 {
		f := ec.listeners.values()[0]
		f(e) or {
			if g := options.error_handler {
				g(0, err)
			}
		}
		return
	}
}

struct Foo {}

struct Bar {}

fn main() {
	foo := EventController[Foo]{}
	println(foo)
	assert foo.id == 0
	bar := EventController[Bar]{}
	println(bar)
	assert bar.id == 0
}

PS D:\Test\v\tt1> v run .
EventController[Foo]{
    id: 0
    listeners: {}
}
EventController[Bar]{
    id: 0
    listeners: {}
}

@spytheman
Copy link
Member

(the CI failure is unrelated (transient network problem))

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
Copy link
Member

The gcc CI job seems stuck, and will probably fail too 🤔.
I should definitely implement periodic dumping of the current state of the test runner.

@spytheman spytheman merged commit c0321c8 into vlang:master Dec 21, 2023
52 of 54 checks passed
@yuyi98 yuyi98 deleted the fix_generic_method_call branch December 21, 2023 15:25
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.

Cgen uses wrong type
2 participants