-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
generics: Generic function not accepting nil as an argument #51729
Comments
Problem is the line that is passing |
working as intended, |
But if there is a function with the argument of type |
I think this issue should not be closed without a discussion. The point i have raised about the ability to pass |
You can always provide the type parameter explicitly, e.g. |
@alwindoss There is a difference in using a variable of interface type and using a constraint of interface type. I wouldn't call it an ambiguity. A variable of interface type can be set to |
Thanks @randall77 for showing how to make it work and @ianlancetaylor for explaining the difference. I modified the program and ran and it passes. It passes because now it has a type that satisfies the constraint |
Just a thought @ianlancetaylor |
I thought about it but I think it would be too complicated to put into the tutorial. I don't think it's something that people new to Go are likely to run into. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I ran this program. Code in Play
What did you expect to see?
For the code to run without errors
What did you see instead?
./main.go:10:20: cannot infer T (/home/alwin/Sandbox/dev/tap/main.go:14:13)
The text was updated successfully, but these errors were encountered: