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
false error when inserting an interface into a map #39911
Comments
yet |
Just my two cents here: According to Go's assignment semantic (https://golang.org/ref/spec#Assignability), functions are expected to be of identical type in assignment context, even though hash.Hash32 is indeed assignment compatible to hash.Hash. |
(func() hash.Hash32) and (func() hash.Hash) are distinct, non-interface types. That Hash32 happens to implement Hash doesn't make it possible to assign a value of the first type to a variable of the other type. You can assign a value of Hash32 to a variable of type Hash, but you can not assign a value of type (func() hash.Hash32) to a variable of type (func() hash.Hash). |
This is rather unfortunate as I feel it should be an allowed assignment, though since the behavior is documented I'm willing to close the issue if this ends up being the final say. |
This is the root if why I believe this is an error. |
The compiler is behaving correctly according to the language definition, so closing the issue. See https://golang.org/doc/faq#covariant_types. For further discussion of why the language works this way, please use a forum; see https://golang.org/wiki/Questions. Thanks. |
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?
https://play.golang.org/p/3zMyaRx10_z
What did you expect to see?
true
What did you see instead?
./prog.go:14:21: cannot use adler32.New (type func() hash.Hash32) as type func() hash.Hash in assignment
The text was updated successfully, but these errors were encountered: