You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implementation restriction: Although numeric constants have arbitrary precision in the language, a compiler may implement them using an internal representation with limited precision. That said, every implementation must:
Represent integer constants with at least 256 bits.
Represent floating-point constants, including the parts of a complex constant, with a mantissa of at least 256 bits and a signed binary exponent of at least 16 bits.
Give an error if unable to represent an integer constant precisely.
Give an error if unable to represent a floating-point or complex constant due to overflow.
So it's okay for go/types to accept it; but since the exponent exceeds 16 bits, it's also okay for cmd/compile to reject it with an error.
However, we could definitely emit a better error message. This is the TODO in gc/mpfloat.go:
f, ok := a.Val.SetString(as)
if !ok {
// At the moment we lose precise error cause;
// the old code additionally distinguished between:
// - malformed hex constant
// - decimal point in hex constant
// - constant exponent out of range
// - decimal point and binary point in constant
// TODO(gri) use different conversion function or check separately
yyerror("malformed constant: %s", as)
mdempsky
changed the title
cmd/compile, go/types: disagreement about whether 6e5518446744 is well-formed
cmd/compile: better error message for bad constants
May 4, 2017
https://play.golang.org/p/_x_9PkQc5F
go/types says yes.
cmd/compile says no:
The text was updated successfully, but these errors were encountered: