diff options
author | Robert Griesemer <gri@golang.org> | 2020-11-18 17:05:02 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2020-11-19 01:27:31 +0000 |
commit | 96b943a483dca715ea0164644e1192052105881a (patch) | |
tree | 668f510f5afc24a20e10986383875a454872d8bf /src/go/types/expr.go | |
parent | 35693d037f9d1c30d6de1fafd08e8c923a415ab8 (diff) | |
download | go-96b943a483dca715ea0164644e1192052105881a.tar.gz go-96b943a483dca715ea0164644e1192052105881a.zip |
go/types: report an error for invalid constant values
The parser reports syntactic errors in constant literals.
The go/constant package produces an "unknown" value for
syntactically correct numeric constants that are too small
or too large. Check for the unknown value and report an
error rather than silently continuing.
Fixes #42695.
Change-Id: I414214559a285d67ed50184dc750f106960b5620
Reviewed-on: https://go-review.googlesource.com/c/go/+/271377
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/go/types/expr.go')
-rw-r--r-- | src/go/types/expr.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 11f9411284..b026e99ce2 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1073,7 +1073,11 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { case *ast.BasicLit: x.setConst(e.Kind, e.Value) if x.mode == invalid { - check.invalidAST(e, "invalid literal %v", e.Value) + // The parser already establishes syntactic correctness. + // If we reach here it's because of number under-/overflow. + // TODO(gri) setConst (and in turn the go/constant package) + // should return an error describing the issue. + check.errorf(e, _InvalidConstVal, "malformed constant: %s", e.Value) goto Error } |