go/internal/gcimporter: ensure that imported floats are of float kind As of CL 290630, go/types enforces some bitsize limits on integer const values. We need to be careful to preserve the constant Kind when importing from gc export data. Ideally we could follow CL 288632, but the go/constant APIs used in that CL are not available to x/tools, which (at least for the moment) must still build at go1.12. Instead, simply call constant.ToFloat to force the Kind. Add a test for the imported Kind. This test should probably also be upstreamed to std/go/internal/gcimporter, now that go/types relies on this behavior. Change-Id: I84b4b15b398962305aa6e3e9e12ede6a7373230b Reviewed-on: https://go-review.googlesource.com/c/tools/+/307590 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
diff --git a/go/internal/gcimporter/iimport.go b/go/internal/gcimporter/iimport.go index b236deb..8ed8bc6 100644 --- a/go/internal/gcimporter/iimport.go +++ b/go/internal/gcimporter/iimport.go
@@ -473,6 +473,14 @@ switch { case exp > 0: x = constant.Shift(x, token.SHL, uint(exp)) + // Ensure that the imported Kind is Float, else this constant may run into + // bitsize limits on overlarge integers. Eventually we can instead adopt + // the approach of CL 288632, but that CL relies on go/constant APIs that + // were introduced in go1.13. + // + // TODO(rFindley): sync the logic here with tip Go once we no longer + // support go1.12. + x = constant.ToFloat(x) case exp < 0: d := constant.Shift(constant.MakeInt64(1), token.SHL, uint(-exp)) x = constant.BinaryOp(x, token.QUO, d)