]> Cypherpunks repositories - gostls13.git/commitdiff
gc: line number + type checking nits
authorRuss Cox <rsc@golang.org>
Thu, 28 Jul 2011 16:31:16 +0000 (12:31 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 28 Jul 2011 16:31:16 +0000 (12:31 -0400)
Fixes #1910.
Fixes #1979.
Fixes #1990.
Fixes #1993.
Fixes #2089.

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

src/cmd/gc/go.y
src/cmd/gc/lex.c
src/cmd/gc/typecheck.c
test/fixedbugs/bug274.go
test/fixedbugs/bug298.go
test/fixedbugs/bug353.go [new file with mode: 0644]
test/fixedbugs/bug357.go [new file with mode: 0644]
test/fixedbugs/bug358.go [new file with mode: 0644]
test/fixedbugs/bug359.go [new file with mode: 0644]

index 36b549ddea29373a6d6b526564d5aa2dd684e40d..4c7fe6068b2653a1b445b2fe7ecaea2975297978 100644 (file)
@@ -1249,7 +1249,10 @@ fnliteral:
                $$ = closurebody($3);
                fixlbrace($2);
        }
-
+|      fnlitdcl error
+       {
+               $$ = closurebody(nil);
+       }
 
 /*
  * lists of things
index 24a244e40fec680c72354bdc98e029cfb40eda80..29b6d27ffc538b2fc7c39e599d746e06ee058f7d 100644 (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)
index 81b9dd2c86b23e57893f3d1ef00e6a60bf9bc6d4..78cdb5bf232089f501433d8483dc6821a88e5ff4 100644 (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);
index 81ee9e5b8a8cb31d10f758158dfd68ad63b732ff..198544c3f5425104923e6112ea0b30cdbf6ffb63 100644 (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:
        }
 }
index fe4a99a780ec9908b7f4d2c5237ccbf640a17588..c16c3f98af196a35d73ea52903e5356799af7446 100644 (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"
 
diff --git a/test/fixedbugs/bug353.go b/test/fixedbugs/bug353.go
new file mode 100644 (file)
index 0000000..46f5c36
--- /dev/null
@@ -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)
+}
diff --git a/test/fixedbugs/bug357.go b/test/fixedbugs/bug357.go
new file mode 100644 (file)
index 0000000..2220398
--- /dev/null
@@ -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
+}
diff --git a/test/fixedbugs/bug358.go b/test/fixedbugs/bug358.go
new file mode 100644 (file)
index 0000000..cc622c0
--- /dev/null
@@ -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
+}
+
diff --git a/test/fixedbugs/bug359.go b/test/fixedbugs/bug359.go
new file mode 100644 (file)
index 0000000..6ced608
--- /dev/null
@@ -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"
+}