Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
spec: clarify requirements for duplicate constants in interface-typed map literal keys and switches #28085
The Go spec disallows duplicate constants in map literal keys, and allows compilers to reject duplicate constants in switch cases.
However, the Go spec does not formally allow interface-typed constants, and doesn't mention how to handle constants that are implicitly or explicitly converted to interface type. The existing compilers handle these situations in differing ways:
cmd/compile rejects 1, 2, and 3.
go/types rejects 1 and 3.
gccgo (8.0) rejects none.
Consistent logic for handling both duplicate map keys and case values, and eliminates ad hoc value hashing code. Also makes cmd/compile consistent with go/types's handling of duplicate constants (see #28085), which is at least an improvement over the status quo even if we settle on something different for the spec. As a side effect, this also suppresses cmd/compile's warnings about duplicate nils in (non-interface expression) switch statements, which was technically never allowed by the spec anyway. Updates #28085. Updates #28378. Change-Id: I176a251e770c3c5bc11c2bf8d1d862db8f252a17 Reviewed-on: https://go-review.googlesource.com/c/152544 Run-TryBot: Matthew Dempsky <email@example.com> TryBot-Result: Gobot Gobot <firstname.lastname@example.org> Reviewed-by: Robert Griesemer <email@example.com>