]> Cypherpunks repositories - gostls13.git/commitdiff
gc: do not try to add a key with incorrect type to a hash
authorJeff R. Allen <jra@nella.org>
Fri, 20 Jan 2012 18:34:38 +0000 (13:34 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 20 Jan 2012 18:34:38 +0000 (13:34 -0500)
Fixes #2623.

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5533043

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

index f4294ae7af2bd39cd93bbe799f990708822b6eda..1092608dc9504e0ec503589ba440d25014278dbb 100644 (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);
diff --git a/test/fixedbugs/bug397.go b/test/fixedbugs/bug397.go
new file mode 100644 (file)
index 0000000..cc8bfc0
--- /dev/null
@@ -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"
+}