@@ -595,27 +595,29 @@ It is a compile-time error if:
595
595
596
596
* Any of the entry key expressions are not constant expressions.
597
597
598
- * If any two keys in the map are identical. * Map patterns that don't have a
599
- rest element only match if the ` length ` of the map is equal to the number of
600
- map entries. If a map pattern has multiple identical key entries, they will
598
+ * Any two keys in the map are identical. * Map patterns that don't have a rest
599
+ element only match if the ` length ` of the map is equal to the number of map
600
+ entries. If a map pattern has multiple identical key entries, they will
601
601
increase the required length for the pattern to match but in all but the
602
602
most perverse ` Map ` implementations will represent the same key. Thus, it's
603
603
very unlikely that any map pattern containing identical keys (and no rest
604
604
element) will ever match. Duplicate keys are most likely a typo in the
605
605
code.*
606
606
607
- * If any two keys in the map both have primitive ` == ` methods, then it is a
608
- compile-time error if they are equal according to their ` == ` operator. * In
609
- cases where keys have types whose equality can be checked at compile time,
610
- we report errors if there are redundant keys. But we don't require the keys
611
- to have primitive equality for flexibility. In map patterns where the keys
612
- don't have primitive equality, it is possible to have redundant keys and the
613
- compiler won't detect it.*
607
+ * Any two record keys which both have primitive ` == ` are equal. * Since
608
+ records don't have defined identity, we can't use the previous rule to
609
+ detect identical records. But records do support an equality test known at
610
+ compile time if all of their fields do, so we use that.*
614
611
615
612
* There is more than one ` ... ` element in the map pattern.
616
613
617
614
* The ` ... ` element is not the last element in the map pattern.
618
615
616
+ * Note that we don't require map keys to have primitive ` == ` methods to enable
617
+ more flexibility in key types. If the keys have user-defined ` == ` methods, then
618
+ it's possible to have keys that are equal according to those ` == ` methods, but
619
+ the compiler won't detect it.*
620
+
619
621
### Rest elements
620
622
621
623
Like lists, map patterns can also have a rest element. However, there's no
@@ -3221,6 +3223,8 @@ Here is one way it could be broken down into separate pieces:
3221
3223
3222
3224
- Clarify which variables are valid in pattern assignments.
3223
3225
3226
+ - Clarify when primitive `==` for map pattern keys comes into play (#2690).
3227
+
3224
3228
### 2.19
3225
3229
3226
3230
- Specify exhaustiveness checking of switch elements.
0 commit comments