1
0
mirror of https://github.com/golang/go synced 2024-11-24 05:50:13 -07:00

gc: handle use of builtin function outside function call

tweaks & tests of last bug fix too.

R=ken2
CC=golang-dev
https://golang.org/cl/1207044
This commit is contained in:
Russ Cox 2010-05-20 22:57:08 -07:00
parent b03d7f4d8f
commit 709c5b2481
4 changed files with 23 additions and 3 deletions

View 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;

View 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;
}

View 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}

14
test/varerr.go Normal file
View File

@ -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"
}