summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-05-20 22:57:08 -0700
committerRuss Cox <rsc@golang.org>2010-05-20 22:57:08 -0700
commit05a0e2fa64ad9c2ad69a12630313ba68c68de9ee (patch)
treec9e33bdcddfa36b85a97e6ece0b33c06e67382d6
parent9c07dc28bc9ff5e7d1e149f2413b7c101a4cd562 (diff)
downloadgolang-05a0e2fa64ad9c2ad69a12630313ba68c68de9ee.tar.gz
gc: handle use of builtin function outside function call
tweaks & tests of last bug fix too. R=ken2 CC=golang-dev http://codereview.appspot.com/1207044
-rw-r--r--src/cmd/gc/typecheck.c4
-rw-r--r--src/cmd/gc/walk.c4
-rw-r--r--test/fixedbugs/bug208.go4
-rw-r--r--test/varerr.go14
4 files changed, 23 insertions, 3 deletions
diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c
index 707546b10..b6940d412 100644
--- a/src/cmd/gc/typecheck.c
+++ b/src/cmd/gc/typecheck.c
@@ -89,6 +89,10 @@ typecheck(Node **np, int top)
redo:
lno = setlineno(n);
if(n->sym) {
+ if(n->op == ONAME && n->etype != 0) {
+ yyerror("use of builtin %S not in function call", n->sym);
+ goto error;
+ }
walkdef(n);
if(n->op == ONONAME)
goto error;
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index 3098fa525..21bd0b56e 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -221,7 +221,9 @@ walkdef(Node *n)
if(n->op == ONONAME) {
if(!n->diag) {
n->diag = 1;
- yyerrorl(n->lineno, "undefined: %S", n->sym);
+ if(n->lineno != 0)
+ lineno = n->lineno;
+ yyerror("undefined: %S", n->sym);
}
return;
}
diff --git a/test/fixedbugs/bug208.go b/test/fixedbugs/bug208.go
index 0a05d80c1..13b040084 100644
--- a/test/fixedbugs/bug208.go
+++ b/test/fixedbugs/bug208.go
@@ -11,10 +11,10 @@ type T struct
f int;
}
-var _ = T{f: 1}
-
// 6g used to get confused by the f:1 above
// and allow uses of f that would be silently
// dropped during the compilation.
var _ = f; // ERROR "undefined"
+var _ = T{f: 1}
+
diff --git a/test/varerr.go b/test/varerr.go
new file mode 100644
index 000000000..32f33ecc7
--- /dev/null
+++ b/test/varerr.go
@@ -0,0 +1,14 @@
+// errchk $G $D/$F.go
+
+// Copyright 2010 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.
+
+package main
+
+func main() {
+ _ = asdf // ERROR "undefined: asdf"
+
+ new = 1 // ERROR "use of builtin new not in function call"
+}
+