aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/scanner_test.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2019-08-28 21:56:47 -0700
committerRobert Griesemer <gri@golang.org>2019-08-29 23:37:01 +0000
commit117400ec095335f24e5363f61d60f8baad6be3ce (patch)
treeffa7bafc79f21110766afc3bb8f96d3dad1974bd /src/cmd/compile/internal/syntax/scanner_test.go
parentbf36219cdd1d354d58107ed8903679f538948154 (diff)
downloadgo-117400ec095335f24e5363f61d60f8baad6be3ce.tar.gz
go-117400ec095335f24e5363f61d60f8baad6be3ce.zip
cmd/compile/internal/syntax: add BasicLit.Bad field for lexical errors
The new (internal) field scanner.bad indicates whether a syntax error occurred while scanning a literal; the corresponding scanner.lit string may be syntactically incorrect in that case. Store the value of scanner.bad together with the scanner.lit in BasicLit. Clean up error handling so that all syntactic errors use one of the scanner's error reporting methods which also set scanner.bad. Make use of the new field in a few places where we used to track a prior error separately. Preliminary step towards fixing #32133 in a comprehensive manner. Change-Id: I4d79ad6e3b50632dd5fb3fc32ca3df0598ee77b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/192278 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/scanner_test.go')
-rw-r--r--src/cmd/compile/internal/syntax/scanner_test.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/syntax/scanner_test.go b/src/cmd/compile/internal/syntax/scanner_test.go
index bfc44950be..3030bfd4c0 100644
--- a/src/cmd/compile/internal/syntax/scanner_test.go
+++ b/src/cmd/compile/internal/syntax/scanner_test.go
@@ -499,6 +499,10 @@ func TestNumbers(t *testing.T) {
err = ""
s.next()
+ if err != "" && !s.bad {
+ t.Errorf("%q: got error but bad not set", test.src)
+ }
+
// compute lit where where s.lit is not defined
var lit string
switch s.tok {
@@ -598,7 +602,7 @@ func TestScanErrors(t *testing.T) {
{`"\x`, "string not terminated", 0, 0},
{`"\x"`, "non-hex character in escape sequence: \"", 0, 3},
{`var s string = "\x"`, "non-hex character in escape sequence: \"", 0, 18},
- {`return "\Uffffffff"`, "escape sequence is invalid Unicode code point", 0, 18},
+ {`return "\Uffffffff"`, "escape sequence is invalid Unicode code point U+FFFFFFFF", 0, 18},
// former problem cases
{"package p\n\n\xef", "invalid UTF-8 encoding", 2, 0},