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

generic type lamda params infer error #1765

Closed
visualfc opened this issue Feb 21, 2024 · 0 comments · Fixed by #1826
Closed

generic type lamda params infer error #1765

visualfc opened this issue Feb 21, 2024 · 0 comments · Fixed by #1826
Labels

Comments

@visualfc
Copy link
Member

visualfc commented Feb 21, 2024

The following program sample.gop triggers an unexpected result

utils.go

package main

func ListMap[T any](ar []T, fn func(v T) T) {
	for i, v := range ar {
		ar[i] = fn(v)
	}
}

sample.gop

num := [1,2,3,4,5]

ListMap[int](num, x => x * x) // build pass
ListMap(num, x => x)          // build error

println num

Expected result

build pass

Got

sample.gop:4:13: cannot use x => x (type func(x T) T) as type func(v int) int in argument to ListMap(num,x => x)

Gop Version

main version

Additional Notes

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants