go: cmd/compile: incorrect error message when assigning an interface to a constant
What version of Go are you using (go version)?
go version devel +68c7cb25a7 Wed Apr 4 12:18:29 2018 +0100 darwin/amd64
Does this issue reproduce with the latest release?
Yes (go version go1.10.1 darwin/amd64).
What did you do?
Compiled https://play.golang.org/p/jzbFN6k7Jhk
What did you expect to see?
./const.go:10:7: const initializer I((*T)(nil)) is not a constant
What did you see instead?
./const.go:10:12: cannot convert (*T)(nil) (type *T) to type I:
*T does not implement I (missing F method)
*T does implement I so this error message is wrong. The real issue is that the RHS is not a valid constant.
Note that the correct error message is shown if the declaration of F() is moved to be above the assertion in the file (i.e. https://play.golang.org/p/9f2SQfBfteA). If the const is changed to var then the program compiles correctly regardless of where F is declared.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 17 (15 by maintainers)
Let’s leave this alone for 1.11. It’s more subtle that it seems (see my comments on the issue) and it’s definitively not urgent.