Commit 7c4d53c2 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: stop generating garbage when checking map key types

Change-Id: Ib500ee92ae1a3d15f7c9f3f46d238b75184b4304
Reviewed-on: https://go-review.googlesource.com/21382Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 00289c29
......@@ -3018,7 +3018,7 @@ func (p *parser) hidden_type_misc() *Type {
p.want(']')
s5 := p.hidden_type()
return maptype(s3, s5)
return typMap(s3, s5)
case LSTRUCT:
// LSTRUCT '{' ohidden_structdcl_list '}'
......
......@@ -372,8 +372,8 @@ func saveorignode(n *Node) {
n.Orig = norig
}
func maptype(key *Type, val *Type) *Type {
if key != nil {
// checkMapKeyType checks that Type key is valid for use as a map key.
func checkMapKeyType(key *Type) {
var bad *Type
atype := algtype1(key, &bad)
var mtype EType
......@@ -403,9 +403,6 @@ func maptype(key *Type, val *Type) *Type {
key.Maplineno = lineno
}
}
}
return typMap(key, val)
}
// methcmp sorts by symbol, then by package path for unexported symbols.
......
......@@ -275,6 +275,10 @@ func typChan(elem *Type, dir uint8) *Type {
// typMap returns a new map Type with key type k and element (aka value) type v.
func typMap(k, v *Type) *Type {
if k != nil {
checkMapKeyType(k)
}
t := typ(TMAP)
t.Down = k
t.Type = v
......
......@@ -402,7 +402,7 @@ OpSwitch:
return n
}
n.Op = OTYPE
n.Type = maptype(l.Type, r.Type)
n.Type = typMap(l.Type, r.Type)
n.Left = nil
n.Right = nil
......@@ -3595,7 +3595,7 @@ ret:
for _, n := range mapqueue {
lineno = n.Type.Maplineno
maptype(n.Type, Types[TBOOL])
checkMapKeyType(n.Type)
}
lineno = lno
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment