diff options
author | Robert Griesemer <gri@golang.org> | 2017-02-08 17:30:45 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2017-02-09 01:45:17 +0000 |
commit | 9799622f09ba2ece6fa8eb7607d0d471d75d9915 (patch) | |
tree | b7e4aaaf7e5ae59cb48ad6035aafa7bb708e97c8 /src/cmd/compile/internal/syntax/scanner_test.go | |
parent | 4f6d4bb3f4461e7e25eff24254115b689495e834 (diff) | |
download | go-9799622f09ba2ece6fa8eb7607d0d471d75d9915.tar.gz go-9799622f09ba2ece6fa8eb7607d0d471d75d9915.zip |
cmd/compile/internal/syntax: differentiate between ';' and '\n' in syntax errors
Towards better syntax error messages: With this change, the parser knows whether
a semicolon was an actual ';' in the source, or whether it was an automatically
inserted semicolon as result of a '\n' or EOF. Using this information in error
messages makes them more understandable.
For #17328.
Change-Id: I8cd9accee8681b62569d0ecef922d38682b401eb
Reviewed-on: https://go-review.googlesource.com/36636
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.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/syntax/scanner_test.go b/src/cmd/compile/internal/syntax/scanner_test.go index fcdc3348e4..ed240df069 100644 --- a/src/cmd/compile/internal/syntax/scanner_test.go +++ b/src/cmd/compile/internal/syntax/scanner_test.go @@ -66,6 +66,11 @@ func TestTokens(t *testing.T) { } switch want.tok { + case _Semi: + if got.lit != "semicolon" { + t.Errorf("got %s; want semicolon", got.lit) + } + case _Name, _Literal: if got.lit != want.src { t.Errorf("got lit = %q; want %q", got.lit, want.src) @@ -94,6 +99,9 @@ func TestTokens(t *testing.T) { t.Errorf("got tok = %s; want ;", got.tok) continue } + if got.lit != "newline" { + t.Errorf("got %s; want newline", got.lit) + } } got.next() |