cmd/compile/internal/syntax: better errors and recovery for invalid character literals

Fixes #15611.

Change-Id: I352b145026466cafef8cf87addafbd30716bda24
Reviewed-on: https://go-review.googlesource.com/37138
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2017-02-16 12:52:01 -08:00
parent 990124da2a
commit 1693e7b6f2
3 changed files with 72 additions and 36 deletions

View file

@ -292,9 +292,9 @@ func TestScanErrors(t *testing.T) {
{`''`, "empty character literal or unescaped ' in character literal", 1, 1},
{"'\n", "newline in character literal", 1, 1},
{`'\`, "missing '", 1, 2},
{`'\'`, "missing '", 1, 3},
{`'\x`, "missing '", 1, 3},
{`'\`, "invalid character literal (missing closing ')", 1, 0},
{`'\'`, "invalid character literal (missing closing ')", 1, 0},
{`'\x`, "invalid character literal (missing closing ')", 1, 0},
{`'\x'`, "non-hex character in escape sequence: '", 1, 3},
{`'\y'`, "unknown escape sequence", 1, 2},
{`'\x0'`, "non-hex character in escape sequence: '", 1, 4},
@ -302,7 +302,8 @@ func TestScanErrors(t *testing.T) {
{`'\377' /*`, "comment not terminated", 1, 7}, // valid octal escape
{`'\378`, "non-octal character in escape sequence: 8", 1, 4},
{`'\400'`, "octal escape value > 255: 256", 1, 5},
{`'xx`, "missing '", 1, 2},
{`'xx`, "invalid character literal (missing closing ')", 1, 0},
{`'xx'`, "invalid character literal (more than one character)", 1, 0},
{"\"\n", "newline in string", 1, 1},
{`"`, "string not terminated", 1, 0},