ulong b;
double d;
int i;
- Node *a;
+ Node *a, *orign;
Node cmp;
char *s;
+ orign = n;
+ if(n->op == OCONVIFACE)
+ n = n->left;
evconst(n);
if(n->op != OLITERAL)
return; // we dont check variables
for(a=hash[h]; a!=N; a=a->ntest) {
cmp.op = OEQ;
cmp.left = n;
- cmp.right = a;
- evconst(&cmp);
- b = cmp.val.u.bval;
+ if(a->op == OCONVIFACE && orign->op == OCONVIFACE) {
+ if(a->left->type == n->type) {
+ cmp.right = a->left;
+ evconst(&cmp);
+ b = cmp.val.u.bval;
+ }
+ else {
+ b = 0;
+ }
+ }
+ else {
+ 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;
}
}
- n->ntest = hash[h];
- hash[h] = n;
+ orign->ntest = hash[h];
+ hash[h] = orign;
}
static void
--- /dev/null
+// errorcheck
+
+// 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.
+
+// Issue 7214: No duplicate key error for maps with interface{} key type
+
+package p
+
+var _ = map[interface{}]int{2: 1, 2: 1} // ERROR "duplicate key"
+var _ = map[interface{}]int{int(2): 1, int16(2): 1}
+var _ = map[interface{}]int{int16(2): 1, int16(2): 1} // ERROR "duplicate key"
+
+type S string
+
+var _ = map[interface{}]int{"a": 1, "a": 1} // ERROR "duplicate key"
+var _ = map[interface{}]int{"a": 1, S("a"): 1}
+var _ = map[interface{}]int{S("a"): 1, S("a"): 1} // ERROR "duplicate key"
+
+type I interface {
+ f()
+}
+
+type N int
+
+func (N) f() {}
+
+var _ = map[I]int{N(0): 1, N(2): 1}
+var _ = map[I]int{N(2): 1, N(2): 1} // ERROR "duplicate key"