]> Cypherpunks repositories - gostls13.git/commitdiff
gc: handle use of builtin function outside function call
authorRuss Cox <rsc@golang.org>
Fri, 21 May 2010 05:57:08 +0000 (22:57 -0700)
committerRuss Cox <rsc@golang.org>
Fri, 21 May 2010 05:57:08 +0000 (22:57 -0700)
tweaks & tests of last bug fix too.

R=ken2
CC=golang-dev
https://golang.org/cl/1207044

src/cmd/gc/typecheck.c
src/cmd/gc/walk.c
test/fixedbugs/bug208.go
test/varerr.go [new file with mode: 0644]

index 707546b1095082dd9c409cd22ddd2ed7109bf94a..b6940d412b756e4f0ac21bac365006fbe55a4fb7 100644 (file)
@@ -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;
index 3098fa525ec188454ebdf2c7a7fde0161104d27b..21bd0b56ea143d6d2f524edf66cd9bf65ae4951d 100644 (file)
@@ -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;
        }
index 0a05d80c1a0e15f3e2a386483f6449bc301c9acf..13b0400848d8fdbdc9ad922beff74e40c5f811b9 100644 (file)
@@ -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 (file)
index 0000000..32f33ec
--- /dev/null
@@ -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"
+}
+