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

cgen: fix generic options with reserved ident (fix #22163) #22164

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 5, 2024

This PR fix generic options with reserved ident (fix #22163).

  • Fix generic options with reserved ident.
  • Add test.
pub fn f[T](defaults ?T) T {
	default := defaults or { T{} }
	dump(default)
	return default
}

fn main() {
	ret1 := f(123)
	println(ret1)
	assert ret1 == 123

	ret2 := f('hello')
	println(ret2)
	assert ret2 == 'hello'
}

PS D:\Test\v\tt1> v run .       
[.\\tt1.v:3] default: 123
123
[.\\tt1.v:3] default: hello
hello

@spytheman
Copy link
Member

Excellent work.
Thank you.

@spytheman spytheman merged commit 633d5f2 into vlang:master Sep 5, 2024
75 checks passed
@yuyi98 yuyi98 deleted the fix_default_var_opt branch September 5, 2024 03:31
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 error for using a default := p or { T{} } construct in a generic function
2 participants