1
0
mirror of https://github.com/golang/go synced 2024-11-14 06:20:23 -07:00

cmd/gc: fix duplicate map key check

Do not compare nil and true.

Fixes #7996.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/91470043
This commit is contained in:
Russ Cox 2014-05-15 15:34:37 -04:00
parent fbd0915008
commit ec38c6f5e3
2 changed files with 17 additions and 7 deletions

View File

@ -2415,23 +2415,19 @@ keydup(Node *n, Node *hash[], ulong nhash)
for(a=hash[h]; a!=N; a=a->ntest) { for(a=hash[h]; a!=N; a=a->ntest) {
cmp.op = OEQ; cmp.op = OEQ;
cmp.left = n; cmp.left = n;
b = 0;
if(a->op == OCONVIFACE && orign->op == OCONVIFACE) { if(a->op == OCONVIFACE && orign->op == OCONVIFACE) {
if(a->left->type == n->type) { if(eqtype(a->left->type, n->type)) {
cmp.right = a->left; cmp.right = a->left;
evconst(&cmp); evconst(&cmp);
b = cmp.val.u.bval; b = cmp.val.u.bval;
} }
else { } else if(eqtype(a->type, n->type)) {
b = 0;
}
}
else {
cmp.right = a; cmp.right = a;
evconst(&cmp); evconst(&cmp);
b = cmp.val.u.bval; b = cmp.val.u.bval;
} }
if(b) { if(b) {
// too lazy to print the literal
yyerror("duplicate key %N in map literal", n); yyerror("duplicate key %N in map literal", n);
return; return;
} }

View File

@ -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: {},
}