Commit 8133cb35 authored by Russ Cox's avatar Russ Cox

gc: preserve original expression for errors

Fixes #1722.

R=ken2
CC=golang-dev
https://golang.org/cl/4442099
parent f319e1df
...@@ -225,6 +225,7 @@ struct Node ...@@ -225,6 +225,7 @@ struct Node
Type* realtype; // as determined by typecheck Type* realtype; // as determined by typecheck
NodeList* list; NodeList* list;
NodeList* rlist; NodeList* rlist;
Node* orig; // original form, for printing
// for-body // for-body
NodeList* ninit; NodeList* ninit;
......
...@@ -1454,6 +1454,8 @@ Nconv(Fmt *fp) ...@@ -1454,6 +1454,8 @@ Nconv(Fmt *fp)
} }
if(fp->flags & FmtSharp) { if(fp->flags & FmtSharp) {
if(n->orig != N)
n = n->orig;
exprfmt(fp, n, 0); exprfmt(fp, n, 0);
goto out; goto out;
} }
......
...@@ -894,12 +894,20 @@ reswitch: ...@@ -894,12 +894,20 @@ reswitch:
// might be constant // might be constant
switch(t->etype) { switch(t->etype) {
case TSTRING: case TSTRING:
if(isconst(l, CTSTR)) if(isconst(l, CTSTR)) {
nodconst(n, types[TINT], l->val.u.sval->len); r = nod(OXXX, N, N);
nodconst(r, types[TINT], l->val.u.sval->len);
r->orig = n;
n = r;
}
break; break;
case TARRAY: case TARRAY:
if(t->bound >= 0 && l->op == ONAME) if(t->bound >= 0 && l->op == ONAME) {
nodconst(n, types[TINT], t->bound); r = nod(OXXX, N, N);
nodconst(r, types[TINT], t->bound);
r->orig = n;
n = r;
}
break; break;
} }
n->type = types[TINT]; n->type = types[TINT];
...@@ -1357,7 +1365,10 @@ ret: ...@@ -1357,7 +1365,10 @@ ret:
goto error; goto error;
} }
if((top & Etop) && !(top & (Ecall|Erv|Etype)) && !(ok & Etop)) { if((top & Etop) && !(top & (Ecall|Erv|Etype)) && !(ok & Etop)) {
if(n->diag == 0) {
yyerror("%#N not used", n); yyerror("%#N not used", n);
n->diag = 1;
}
goto error; goto error;
} }
......
// 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 1722.
// Check that the error messages says
// bug337.go:16: len("foo") not used
// and not
// bug337.go:16: 3 not used
package main
func main() {
len("foo") // ERROR "len"
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment