@@ -621,10 +621,23 @@ func checkDupExprCases(exprname *Node, clauses []*Node) {
621
621
}
622
622
return
623
623
}
624
- // s's expression is an interface. This is fairly rare, so keep this simple.
625
- // Duplicates are only duplicates if they have the same type and the same value.
624
+
625
+ // s's expression is an interface. This is fairly rare, so
626
+ // keep this simple. Case expressions are only duplicates if
627
+ // they have the same value and identical types.
628
+ //
629
+ // In general, we have to use eqtype to test type identity,
630
+ // because == gives false negatives for anonymous types and
631
+ // the byte/uint8 and rune/int32 builtin type aliases.
632
+ // However, this is not a problem here, because constant
633
+ // expressions are always untyped or have a named type, and we
634
+ // explicitly handle the builtin type aliases below.
635
+ //
636
+ // This approach may need to be revisited though if we fix
637
+ // #21866 by treating all type aliases like byte/uint8 and
638
+ // rune/int32.
626
639
type typeVal struct {
627
- typ string
640
+ typ * types. Type
628
641
val interface {}
629
642
}
630
643
seen := make (map [typeVal ]* Node )
@@ -634,9 +647,15 @@ func checkDupExprCases(exprname *Node, clauses []*Node) {
634
647
continue
635
648
}
636
649
tv := typeVal {
637
- typ : n .Type . LongString () ,
650
+ typ : n .Type ,
638
651
val : n .Val ().Interface (),
639
652
}
653
+ switch tv .typ {
654
+ case types .Bytetype :
655
+ tv .typ = types .Types [TUINT8 ]
656
+ case types .Runetype :
657
+ tv .typ = types .Types [TINT32 ]
658
+ }
640
659
prev , dup := seen [tv ]
641
660
if ! dup {
642
661
seen [tv ] = n
0 commit comments