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

parser, checker: fix generic fn variable assignment in generic fn (fix #7287) #18180

Merged
merged 1 commit into from
May 17, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented May 15, 2023

This PR fix generic fn variable assignment in generic fn (fix #7287).

  • Fix generic fn variable assignment in generic fn.
  • Add test.
fn g[T]() u32 {
	return sizeof(T)
}

fn f[T]() u32 {
	p := g[T]
	return p()
}

fn main() {
	r1 := f[int]()
	println(r1)
	assert r1 == 4

	r2 := f[string]()
	println(r2)
	assert r2 == 16

	r3 := f[f64]()
	println(r3)
	assert r3 == 8

	r4 := f[bool]()
	println(r4)
	assert r4 == 1
}

PS D:\Test\v\tt1> v run .
4
16
8
1
fn g[T]() {
	println(sizeof(T))
}

fn f[T]() {
	p := &g[T]
	p()
}

fn main() {
	f[int]()
	f[string]()
}

PS D:\Test\v\tt1> v run .
4
16

@medvednikov medvednikov merged commit ddb8e09 into vlang:master May 17, 2023
@yuyi98 yuyi98 deleted the fix_generic_fn_var branch May 17, 2023 02:54
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.

Can't take address of generic function instantiation
2 participants