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
cmd/compile: incorrect error message when assigning an interface to a constant #24755
Comments
|
Thank you for reporting this @mundaym /cc @mdempsky @griesemer |
Smaller repro:
|
The issue seems to stem from how gc is designed. Reading
So it seems to me like a possible fix would be to insert an extra phase before "variable assignments" called "constant declarations". That way, in our example above, @griesemer @mdempsky thoughts? Is there a better way to fix this issue? (Edit: ended up sending this as a CL - see below) |
I guess that another potential fix would be to detect if we're in phase 1 in the typechecker, and avoid giving errors like |
Change https://golang.org/cl/115096 mentions this issue: |
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. |
Sorry I missed this issue and CL until now. I'm not convinced the committed fix fully addresses this. Typechecking package-scope declarations can't really be split into phases; there's always a way to construct code that depends on any particular kind of declaration being typechecked before any other. E.g., this test case still repros the issue:
(And as a more superficial issue, there are now two phase "3"s in main.go.) |
@mdempsky Agreed, I have also mentioned this in the CL (but the quick test case I tried to create didn't produce an error - see my CL feedback). |
Simpler repro (no need for "unsafe"), same error besides otherwise being incorrect: package p
type x [w]int
type I interface{ F() }
type T struct{}
const w = I(T{})
func (T) F() {} I'm going to roll back the change. |
Change https://golang.org/cl/145617 mentions this issue: |
For what it's worth, while simply typechecking var/type/func declarations separately from const declarations doesn't work, I think the idea I sketched in #13890 to separate package-scope typechecking into "type resolution" and "constant evaluation" phases would work here. |
This reverts commit 9ce87a6. The fix addresses the specific test case, but not the general problem. Updates #24755. Change-Id: I0ba8463b41b099b1ebf49759f88a423b40f70d58 Reviewed-on: https://go-review.googlesource.com/c/145617 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Thanks for the follow-up - looking forward to seeing what a better fix would be like :) |
Too late for 1.12. |
Not sure when this got fixed but the Go playground example now gives the correct error message. Closing this. |
I don't think it does? I'm still seeing the wrong error message ("does not implement") at https://play.golang.org/p/jzbFN6k7Jhk. |
Sorry, yes you're right, I looked at the wrong link. |
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?
What did you see instead?
*T
does implementI
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 theconst
is changed tovar
then the program compiles correctly regardless of where F is declared.The text was updated successfully, but these errors were encountered: