]> Cypherpunks repositories - gostls13.git/commitdiff
gc: bug219, bug239, bug240
authorRuss Cox <rsc@golang.org>
Fri, 8 Jan 2010 07:24:48 +0000 (23:24 -0800)
committerRuss Cox <rsc@golang.org>
Fri, 8 Jan 2010 07:24:48 +0000 (23:24 -0800)
Fixes #475.

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

src/cmd/gc/lex.c
test/fixedbugs/bug219.go [moved from test/bugs/bug219.go with 94% similarity]
test/fixedbugs/bug239.go [moved from test/bugs/bug239.go with 100% similarity]
test/fixedbugs/bug240.go [moved from test/bugs/bug240.go with 91% similarity]

index 43b676d6fccc2e5fd868cb63ca8249650452f8ff..75d6d2200a2b95ecec5d980049ef407733f7742e 100644 (file)
@@ -358,7 +358,6 @@ cannedimports(char *file, char *cp)
        curio.cp = cp;
        curio.nlsemi = 0;
 
-       pkgmyname = S;
        typecheckok = 1;
        incannedimport = 1;
 }
@@ -379,6 +378,12 @@ isfrog(int c)
        return 0;
 }
 
+typedef struct Loophack Loophack;
+struct Loophack {
+       int v;
+       Loophack *next;
+};
+
 static int32
 _yylex(void)
 {
@@ -387,6 +392,8 @@ _yylex(void)
        char *cp;
        Rune rune;
        Sym *s;
+       static Loophack *lstk;
+       Loophack *h;
 
        prevlineno = lineno;
 
@@ -718,18 +725,27 @@ l0:
         * non-parenthesized '{' becomes an LBODY.
         * loophack is normally 0.
         * a keyword makes it go up to 1.
-        * parens increment and decrement when loophack > 0.
+        * parens push loophack onto a stack and go back to 0.
         * a '{' with loophack == 1 becomes LBODY and disables loophack.
         *
         * i said it was clumsy.
         */
        case '(':
-               if(loophack > 0)
-                       loophack++;
+               if(loophack || lstk != nil) {
+                       h = malloc(sizeof *h);
+                       h->v = loophack;
+                       h->next = lstk;
+                       lstk = h;
+                       loophack = 0;
+               }
                goto lx;
        case ')':
-               if(loophack > 0)
-                       loophack--;
+               if(lstk != nil) {
+                       h = lstk;
+                       loophack = h->v;
+                       lstk = h->next;
+                       free(h);
+               }
                goto lx;
        case '{':
                if(loophack == 1) {
similarity index 94%
rename from test/bugs/bug219.go
rename to test/fixedbugs/bug219.go
index aee07cce7e0fc46789983313390af19783c9df70..21361a2aab3d353f52d1d887ae0ea17c89bc4004 100644 (file)
@@ -14,6 +14,7 @@ func g1() {
        if x := f(func() {
                if {}
        }); {
+               _ = x;
        }
 }
 
@@ -22,6 +23,7 @@ func g2() {
        if x := f(func() {
                //if {}
        }); {
+               _ = x;
        }
 }
 
@@ -31,5 +33,6 @@ func g3() {
                if {}
        });
        if {
+               _ = x;
        }
 }
similarity index 100%
rename from test/bugs/bug239.go
rename to test/fixedbugs/bug239.go
similarity index 91%
rename from test/bugs/bug240.go
rename to test/fixedbugs/bug240.go
index dc7cdd8963a563d40441d7c417810a20d6f18eb2..6cba9c8b1e52bec28a21b595311f16f94d4dd11a 100644 (file)
@@ -6,7 +6,7 @@
 
 package main
 
-import . "unsafe"
+import . "unsafe"      // ERROR "not used"
 
 func main() {
        var x int