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 fn infering map argument (fix #18337) #18341

Merged
merged 1 commit into from Jun 4, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jun 4, 2023

This PR fix generic fn infering map argument (fix #18337).

  • Fix generic fn infering map argument.
  • Add test.
fn f[T](src map[string]T) T {
	return src['a']
}

fn main() {
	r1 := f({
		'a': 1
	})
	println(r1)
	assert r1 == 1

	r2 := f({
		'a': 'hello'
	})
	println(r2)
	assert r2 == 'hello'
}

PS D:\Test\v\tt1> v run .
1
hello

@prantlf
Copy link

prantlf commented Jun 4, 2023

I can confirm that this fix works. Thank you!

The real code is a factory function taking any map as input:

r := any_object({
  'a': 1
})
``

@medvednikov medvednikov merged commit 0e106c9 into vlang:master Jun 4, 2023
49 checks passed
@yuyi98 yuyi98 deleted the fix_infer_generic_fn_args branch June 5, 2023 01:23
l1mey112 pushed a commit to l1mey112/v that referenced this pull request Jun 7, 2023
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.

Generic type for map value cannot be inferred from a value argument
3 participants