]> Cypherpunks repositories - gostls13.git/commitdiff
type switch bug involving function parameter names
authorRuss Cox <rsc@golang.org>
Wed, 2 Sep 2009 01:04:49 +0000 (18:04 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 2 Sep 2009 01:04:49 +0000 (18:04 -0700)
R=ken
OCL=34232
CL=34232

src/cmd/gc/subr.c
src/cmd/gc/swt.c
test/fixedbugs/bug200.go [new file with mode: 0644]

index 9eb92f0bbdd8e5763bb27e691f8b7682d3199d46..0c436de0b99f20437159883f23e8e66094db98d2 100644 (file)
@@ -1920,8 +1920,12 @@ typehash(Type *at, int addsym, int d)
                break;
 
        case TSTRUCT:
-               for(t=at->type; t!=T; t=t->down)
-                       h += PRIME7 * typehash(t, addsym, d+1);
+               for(t=at->type; t!=T; t=t->down) {
+                       if(at->funarg)  // walk into TFIELD in function argument struct
+                               h += PRIME7 * typehash(t->type, addsym, d+1);
+                       else
+                               h += PRIME7 * typehash(t, addsym, d+1);
+               }
                break;
 
        case TFUNC:
index 17a4433489488fb4d226ac5307a986112098560e..0754d18f5a5a89801a36908691106f2b412d9f13 100644 (file)
@@ -387,7 +387,7 @@ mkcaselist(Node *sw, int arg)
                                continue;
                        setlineno(c1->link->node);
                        yyerror("duplicate case in switch");
-                       print("    previous case at %L\n",
+                       print("\tprevious case at %L\n",
                                c1->node->lineno);
                }
                break;
@@ -400,7 +400,7 @@ mkcaselist(Node *sw, int arg)
                                continue;
                        setlineno(c1->link->node);
                        yyerror("duplicate case in switch");
-                       print("    previous case at %L\n",
+                       print("\tprevious case at %L\n",
                                c1->node->lineno);
                }
                break;
diff --git a/test/fixedbugs/bug200.go b/test/fixedbugs/bug200.go
new file mode 100644 (file)
index 0000000..123f687
--- /dev/null
@@ -0,0 +1,19 @@
+// errchk $G $D/$F.go
+
+// Copyright 2009 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() {
+       // 6g used to compile these as two different
+       // hash codes so it missed the duplication
+       // and worse, compiled the wrong code
+       // for one of them.
+       var x interface{};
+       switch v := x.(type) {
+       case func(int):
+       case func(f int):       // ERROR "duplicate"
+       }
+}