Skip to content

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

Merged
spytheman merged 1 commit into
vlang:masterfrom
yuyi98:fix_default_var_opt
Sep 5, 2024
Merged

spytheman merged 1 commit into
vlang:masterfrom
yuyi98:fix_default_var_opt

Conversation

@yuyi98

@yuyi98 yuyi98 commented Sep 5, 2024

Copy link
Copy Markdown
Member

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

Excellent work.
Thank you.

@spytheman
spytheman merged commit 633d5f2 into vlang:master Sep 5, 2024
@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