Commit 73d109c5 authored by Russ Cox's avatar Russ Cox Committed by Gerrit Code Review

cmd/internal/gc: accept map literals with omitted key type

Fixes #10209.

Change-Id: I248434f9195c868befd1ed8a6000a9cac72d1df8
Reviewed-on: https://go-review.googlesource.com/10263Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 03410f67
...@@ -1080,7 +1080,7 @@ start_complit: ...@@ -1080,7 +1080,7 @@ start_complit:
} }
keyval: keyval:
expr ':' complitexpr complitexpr ':' complitexpr
{ {
$$ = Nod(OKEY, $1, $3); $$ = Nod(OKEY, $1, $3);
} }
......
...@@ -3056,9 +3056,11 @@ func typecheckcomplit(np **Node) { ...@@ -3056,9 +3056,11 @@ func typecheckcomplit(np **Node) {
continue continue
} }
typecheck(&l.Left, Erv) r = l.Left
defaultlit(&l.Left, t.Down) pushtype(r, t.Down)
l.Left = assignconv(l.Left, t.Down, "map key") typecheck(&r, Erv)
defaultlit(&r, t.Down)
l.Left = assignconv(r, t.Down, "map key")
if l.Left.Op != OCONV { if l.Left.Op != OCONV {
keydup(l.Left, hash) keydup(l.Left, hash)
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -40,3 +40,17 @@ var ( ...@@ -40,3 +40,17 @@ var (
_ = &T{i: 0, f: 0, s: "", next: {}} // ERROR "missing type in composite literal|omit types within composite literal" _ = &T{i: 0, f: 0, s: "", next: {}} // ERROR "missing type in composite literal|omit types within composite literal"
_ = &T{0, 0, "", {}} // ERROR "missing type in composite literal|omit types within composite literal" _ = &T{0, 0, "", {}} // ERROR "missing type in composite literal|omit types within composite literal"
) )
type M map[T]T
var (
_ = M{{i:1}: {i:2}}
_ = M{T{i:1}: {i:2}}
_ = M{{i:1}: T{i:2}}
_ = M{T{i:1}: T{i:2}}
)
type S struct { s [1]*M1 }
type M1 map[S]int
var _ = M1{{s:[1]*M1{&M1{{}:1}}}:2}
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