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
cmd/compile: non-compliant duplicate constant checking #28078
The Go spec disallows duplicate map key constants and allows implementations to restrict duplicate switch case constants. However, in both cases, these must be Go language constants (as the Go spec doesn't have any other notion of "constant".)
This code should be valid, but cmd/compile currently rejects it for having duplicate keys and cases:
gotype accepts it.
(This is yet another bug relating to gc's overly eager constant folding in the frontend.)
FYI, I think this is relatively straight forward to fix: we just need to check isGoConstant() instead of Op==OLITERAL when checking for duplicate constants in composite literals and switch cases. (Moreover, we should probably de-duplicate that logic.)
Also related: #28085.