-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile/internal/types2: "real(0)" and "imag(0)" have type "untyped float", but value of kind constant.Int #43891
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
Comments
FWIW, after CLs 286176, 286214, and 286215, this is the only remaining failure for "GO_GCFLAGS=-G=3 go run run.go". (Note though: errorcheck tests don't use GO_GCFLAGS.) |
It looks like this may actually be a go/constant bug: the Go spec say the |
Incidentally, I'm suspicious of the
This discrepancy is because |
Thanks for tracking this down. There appear to be two separate issues at stake here:
I need to think a bit more on both of these to convince myself of the correct solution. |
Factored out problem 1) into #43908. |
Without actually trying it, I think that's only because the declared constants aren't exported. If they were renamed from "_" to "ExportedConstant" or something, I expect it would cause another crash in the exporter, because the value representation wouldn't match the untyped kind.
Ack. In the mean time, I'll look into adding a workaround/fix in irgen.constDecl, so we can enable |
Change https://golang.org/cl/286652 mentions this issue: |
…expected kind Currently, types2 sometimes produces constant.Values with a Kind different than the untyped constant type's Is{Integer,Float,Complex} info, which irgen expects to always match. While we mull how best to proceed in #43891, this CL adapts irgen to types2's current behavior. In particular, fixedbugs/issue11945.go now passes with -G=3. Updates #43891. Change-Id: I24823a32ff49af6045a032d3903dbb55cbec6bef Reviewed-on: https://go-review.googlesource.com/c/go/+/286652 Run-TryBot: Matthew Dempsky <[email protected]> Trust: Matthew Dempsky <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
I can confirm that the exporter forces a particular constant representation based on type. However, This was not an issue for the compiler before the use of I think we should try to avoid this, but it will require an extra byte of information (the |
Change https://golang.org/cl/292351 mentions this issue: |
The current versions of the indexed export format encode constant values based on their type. However, IExportData was encoding constants values based on their own kind instead. While cmd/compile internally keeps these matched, go/types does not guarantee the same (see also golang/go#43891). This CL fixes this issue, and also extends testing to check reading in the compiler's export data and that imported packages can be exported again. Change-Id: I08f1845f371edd87773df0ef85bcd4e28f5db2f5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/292351 gopls-CI: kokoro <[email protected]> Trust: Matthew Dempsky <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
Confirming that The |
On dev.typeparams,
go tool compile -G=3 $(go env GOROOT)/test/fixedbugs/issue11945.go
currently fails because thereal(0)
andimag(0)
expressions have type "untyped float", but then their go/constant representation has kind constant.Int, whereas irgen expects it to be constant.Float.My intuition is that the TypeAndValue.Value's constant.Kind should always match the TypeAndValue.Type's Underlying's BasicInfo's Is{Boolean,Integer,Float,Complex,String}.
However, if that expectation is incorrect/unreasonable, I think this would be reasonable to handle in irgen instead of types2. (With the recent types2 cleanup, untyped numeric values are only seen in constant declarations. We also already have the constant's type before we set the value, so it wouldn't be hard to coerce to the expected constant.Kind.)
/cc @griesemer @findleyr @danscales
The text was updated successfully, but these errors were encountered: