1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:14:52 -07:00

gc: line number + type checking nits

Fixes #1910.
Fixes #1979.
Fixes #1990.
Fixes #1993.
Fixes #2089.

R=ken2
CC=golang-dev
https://golang.org/cl/4828046
This commit is contained in:
Russ Cox 2011-07-28 12:31:16 -04:00
parent 3041f2a37c
commit 2f8190a8f8
9 changed files with 122 additions and 5 deletions

View File

@ -1249,7 +1249,10 @@ fnliteral:
$$ = closurebody($3);
fixlbrace($2);
}
| fnlitdcl error
{
$$ = closurebody(nil);
}
/*
* lists of things

View File

@ -254,7 +254,7 @@ main(int argc, char *argv[])
resumetypecopy();
resumecheckwidth();
for(l=xtop; l; l=l->next)
for(l=xtop; l; l=l->next) {
if(l->n->op == ODCLFUNC || l->n->op == OCLOSURE) {
curfn = l->n;
saveerrors();
@ -262,7 +262,12 @@ main(int argc, char *argv[])
if(nerrors != 0)
l->n->nbody = nil; // type errors; do not compile
}
}
curfn = nil;
if(nsavederrors+nerrors)
errorexit();
for(l=xtop; l; l=l->next)
if(l->n->op == ODCLFUNC)

View File

@ -146,17 +146,18 @@ typecheck(Node **np, int top)
case OPACK:
break;
default:
lineno = lno;
return n;
}
}
if(n->typecheck == 2) {
yyerror("typechecking loop");
lineno = lno;
return n;
}
n->typecheck = 2;
lno = setlineno(n);
if(n->sym) {
if(n->op == ONAME && n->etype != 0 && !(top & Ecall)) {
yyerror("use of builtin %S not in function call", n->sym);

View File

@ -25,6 +25,7 @@ func main() {
L1: // ERROR "statement"
default:
// correct since no semicolon is required before a '}'
L2: // ERROR "not used"
goto L2
L2:
}
}

View File

@ -7,5 +7,5 @@
package ddd
func Sum() int
for i := range []int{} { return i } // ERROR "return outside function|expected"
for i := range []int{} { return i } // ERROR "statement outside function|expected"

30
test/fixedbugs/bug353.go Normal file
View File

@ -0,0 +1,30 @@
// 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 2089 - internal compiler error
package main
import (
"io"
"os"
)
func echo(fd io.ReadWriterCloser) { // ERROR "undefined: io.ReadWriterCloser"
var buf [1024]byte
for {
n, err := fd.Read(buf)
if err != nil {
break
}
fd.Write(buf[0:n])
}
}
func main() {
fd, _ := os.Open("a.txt")
echo(fd)
}

25
test/fixedbugs/bug357.go Normal file
View File

@ -0,0 +1,25 @@
// 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 1993.
// error used to have last line number in file
package main
func bla1() bool {
return false
}
func bla5() bool {
_ = 1
false // ERROR "false not used"
_ = 2
}
func main() {
x := bla1()
_ = x
}

26
test/fixedbugs/bug358.go Normal file
View File

@ -0,0 +1,26 @@
// 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 1979
// used to get internal compiler error too
package main
import (
"http"
"io/ioutil"
"os"
)
func makeHandler(fn func(http.ResponseWriter, *http.Request, string)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) // ERROR "syntax error"
}
type Page struct {
Title string
Body []byte
}

26
test/fixedbugs/bug359.go Normal file
View File

@ -0,0 +1,26 @@
// 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 1910
// error on wrong line
package main
import "container/list"
type Painting struct {
fragments list.List // private
}
func (p Painting) Foo() {
for e := p.fragments; e.Front() != nil; e = e.Next() { // ERROR "unexported field"
}
}
// from comment 4 of issue 1910
type Foo interface {
Run(a int) (a int) // ERROR "a redeclared"
}