]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix duplicate map key check
authorRuss Cox <rsc@golang.org>
Thu, 15 May 2014 19:34:37 +0000 (15:34 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 15 May 2014 19:34:37 +0000 (15:34 -0400)
Do not compare nil and true.

Fixes #7996.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/91470043

src/cmd/gc/typecheck.c
test/fixedbugs/issue7996.go [new file with mode: 0644]

index b51fc3892a88f7501f56c4f2cc9c67bc323d5d0f..c50b2285b67da92c135f8d121de8356212b68213 100644 (file)
@@ -2415,23 +2415,19 @@ keydup(Node *n, Node *hash[], ulong nhash)
        for(a=hash[h]; a!=N; a=a->ntest) {
                cmp.op = OEQ;
                cmp.left = n;
+               b = 0;
                if(a->op == OCONVIFACE && orign->op == OCONVIFACE) {
-                       if(a->left->type == n->type) {
+                       if(eqtype(a->left->type, n->type)) {
                                cmp.right = a->left;
                                evconst(&cmp);
                                b = cmp.val.u.bval;
                        }
-                       else {
-                               b = 0;
-                       }
-               }
-               else {
+               } else if(eqtype(a->type, n->type)) {
                        cmp.right = a;
                        evconst(&cmp);
                        b = cmp.val.u.bval;
                }
                if(b) {
-                       // too lazy to print the literal
                        yyerror("duplicate key %N in map literal", n);
                        return;
                }
diff --git a/test/fixedbugs/issue7996.go b/test/fixedbugs/issue7996.go
new file mode 100644 (file)
index 0000000..98289eb
--- /dev/null
@@ -0,0 +1,14 @@
+// compile
+
+// Copyright 2014 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.
+
+// /tmp/x.go:5: illegal constant expression: bool == interface {}
+
+package p
+
+var m = map[interface{}]struct{}{
+       nil:  {},
+       true: {},
+}