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

v: fix generic lambda type binding and resolution #22083

Merged
merged 4 commits into from
Aug 23, 2024

Conversation

felipensp
Copy link
Member

Fix #19426

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.

Will the same approach work for generic functions, calling other generic functions, with a LambdaExpr ?

Try adding such an example in the test case too, with |x,y| x + y, where x and y are in one call 2 ints, and in another call, 2 strings .

@JalonSolov
Copy link
Contributor

Perhaps a 3rd case where one is an int and the other a string, for a known error case?

@felipensp
Copy link
Member Author

Excellent work.

Will the same approach work for generic functions, calling other generic functions, with a LambdaExpr ?

Try adding such an example in the test case too, with |x,y| x + y, where x and y are in one call 2 ints, and in another call, 2 strings .

Yeah, Just tested:

fn ddd[T](call fn (arg1 T, arg2 T) string, arg1 T, arg2 T) string {
	return call(arg1, arg2)
}

fn abc[T](arg1 T, arg2 T) string {
	return ddd(|x,y| (x+y).str(), arg1, arg2)
}

fn main() {
	abc('3', '3')
	abc(3, 3)	
	abc(3.1, 3.1)	
}

It needs more work to make it possible... I'll check it.

@felipensp
Copy link
Member Author

felipensp commented Aug 22, 2024

Excellent work.
Will the same approach work for generic functions, calling other generic functions, with a LambdaExpr ?
Try adding such an example in the test case too, with |x,y| x + y, where x and y are in one call 2 ints, and in another call, 2 strings .

Yeah, Just tested:

fn ddd[T](call fn (arg1 T, arg2 T) string, arg1 T, arg2 T) string {
	return call(arg1, arg2)
}

fn abc[T](arg1 T, arg2 T) string {
	return ddd(|x,y| (x+y).str(), arg1, arg2)
}

fn main() {
	abc('3', '3')
	abc(3, 3)	
	abc(3.1, 3.1)	
}

It needs more work to make it possible... I'll check it.

I've handled this case. Have you any other test case? @spytheman

@felipensp felipensp changed the title v: generic lambda v: fix generic lambda type binding and resolution Aug 23, 2024
@felipensp felipensp marked this pull request as ready for review August 23, 2024 15:29
@spytheman
Copy link
Member

I could not think of any other @felipensp .

Excellent work.

@spytheman spytheman merged commit 484cd83 into vlang:master Aug 23, 2024
73 checks passed
@felipensp felipensp deleted the fix_generic_lambda branch August 23, 2024 16:46
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.

Lambda not working with generics
3 participants