aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-07-27 14:36:21 -0400
committerRuss Cox <rsc@golang.org>2011-07-27 14:36:21 -0400
commit49b70d01c07be39ede5f4431d0f36415d01f676d (patch)
treee13de60afbe11224362a497955df15d2debcbeac
parent100a034120e7f68ba5ca687b98bb930f4f539b9b (diff)
downloadgo-49b70d01c07be39ede5f4431d0f36415d01f676d.tar.gz
go-49b70d01c07be39ede5f4431d0f36415d01f676d.zip
gc: echo literal in error message
Fixes #1192. R=ken2 CC=golang-dev https://golang.org/cl/4794062
-rw-r--r--src/cmd/gc/go.h1
-rw-r--r--src/cmd/gc/lex.c14
-rw-r--r--test/fixedbugs/bug349.go13
3 files changed, 28 insertions, 0 deletions
diff --git a/src/cmd/gc/go.h b/src/cmd/gc/go.h
index f7d6597603..dfc5887a5c 100644
--- a/src/cmd/gc/go.h
+++ b/src/cmd/gc/go.h
@@ -698,6 +698,7 @@ EXTERN int nsyntaxerrors;
EXTERN int safemode;
EXTERN char namebuf[NSYMB];
EXTERN char lexbuf[NSYMB];
+EXTERN char litbuf[NSYMB];
EXTERN char debug[256];
EXTERN Sym* hash[NHASH];
EXTERN Sym* importmyname; // my name for package
diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c
index 5c642375a3..21ac779a9f 100644
--- a/src/cmd/gc/lex.c
+++ b/src/cmd/gc/lex.c
@@ -728,6 +728,7 @@ l0:
yylval.val.u.sval = (Strlit*)cp;
yylval.val.ctype = CTSTR;
DBG("lex: string literal\n");
+ strcpy(litbuf, "string literal");
return LLITERAL;
case '\'':
@@ -744,6 +745,7 @@ l0:
mpmovecfix(yylval.val.u.xval, v);
yylval.val.ctype = CTINT;
DBG("lex: codepoint literal\n");
+ strcpy(litbuf, "string literal");
return LLITERAL;
case '/':
@@ -1133,6 +1135,8 @@ ncu:
}
yylval.val.ctype = CTINT;
DBG("lex: integer literal\n");
+ strcpy(litbuf, "literal ");
+ strcat(litbuf, lexbuf);
return LLITERAL;
casedot:
@@ -1205,6 +1209,8 @@ casei:
}
yylval.val.ctype = CTCPLX;
DBG("lex: imaginary literal\n");
+ strcpy(litbuf, "literal ");
+ strcat(litbuf, lexbuf);
return LLITERAL;
caseout:
@@ -1219,6 +1225,8 @@ caseout:
}
yylval.val.ctype = CTFLT;
DBG("lex: floating literal\n");
+ strcpy(litbuf, "literal ");
+ strcat(litbuf, lexbuf);
return LLITERAL;
}
@@ -1859,6 +1867,12 @@ yytinit(void)
for(i=0; yytname[i] != nil; i++) {
s = yytname[i];
+ if(strcmp(s, "LLITERAL") == 0) {
+ strcpy(litbuf, "literal");
+ yytname[i] = litbuf;
+ goto loop;
+ }
+
// apply yytfix if possible
for(j=0; j<nelem(yytfix); j++) {
if(strcmp(s, yytfix[j].have) == 0) {
diff --git a/test/fixedbugs/bug349.go b/test/fixedbugs/bug349.go
new file mode 100644
index 0000000000..07005973e7
--- /dev/null
+++ b/test/fixedbugs/bug349.go
@@ -0,0 +1,13 @@
+// errchk $G $D/$F.go
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// issue 1192 - detail in error
+
+package main
+
+func foo() (a, b, c int) {
+ return 0, 1 2.01 // ERROR "unexpected literal 2.01"
+}