1
0
mirror of https://github.com/golang/go synced 2024-11-11 20:01:37 -07:00

gc: do not try to add a key with incorrect type to a hash

Fixes #2623.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5533043
This commit is contained in:
Jeff R. Allen 2012-01-20 13:34:38 -05:00 committed by Russ Cox
parent 541978af0a
commit 46e7cb57c9
2 changed files with 15 additions and 1 deletions

View File

@ -2130,7 +2130,8 @@ typecheckcomplit(Node **np)
typecheck(&l->left, Erv);
defaultlit(&l->left, t->down);
l->left = assignconv(l->left, t->down, "map key");
keydup(l->left, hash, nhash);
if (l->left->op != OCONV)
keydup(l->left, hash, nhash);
r = l->right;
pushtype(r, t->type);

13
test/fixedbugs/bug397.go Normal file
View File

@ -0,0 +1,13 @@
// errchk $G -e $D/$F.go
// Copyright 2011 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
// Issue 2623
var m = map[string]int {
"abc":1,
1:2, // ERROR "cannot use 1.*as type string in map key"
}