@@ -4,7 +4,7 @@ Author: Bob Nystrom
4
4
5
5
Status: In progress
6
6
7
- Version 2.0 (see [ CHANGELOG] ( #CHANGELOG ) at end)
7
+ Version 2.2 (see [ CHANGELOG] ( #CHANGELOG ) at end)
8
8
9
9
Note: This proposal is broken into a couple of separate documents. See also
10
10
[ records] [ ] and [ exhaustiveness] [ ] .
@@ -1584,7 +1584,9 @@ The variables a patterns binds depend on what kind of pattern it is:
1584
1584
1585
1585
* ** Variable** or ** cast** : May contain type argument patterns. Introduces a
1586
1586
variable whose name is the pattern's identifier. The variable is final if
1587
- the surrounding pattern variable declaration has a ` final ` modifier.
1587
+ the surrounding ` patternDeclaration ` has a ` final ` modifier. * Variables in
1588
+ switch cases don't occur inside pattern variable declarations and thus are
1589
+ not final.*
1588
1590
1589
1591
The scope where a pattern's variables are declared depends on the construct
1590
1592
that contains the pattern:
@@ -1825,7 +1827,12 @@ To match a pattern `p` against a value `v`:
1825
1827
some ` K ` and ` V ` determined either by the pattern's explicit type
1826
1828
arguments or inferred from the matched value type.*
1827
1829
1828
- 2 . Otherwise, for each entry in ` p ` :
1830
+ 2 . If the length of the map determined by calling ` length ` is not equal to
1831
+ the number of subpatterns, then the match fails. * This match failure
1832
+ becomes a runtime exception if the map pattern is in a variable
1833
+ declaration.*
1834
+
1835
+ 3 . Otherwise, for each entry in ` p ` :
1829
1836
1830
1837
1 . Evaluate the key ` expression ` to ` k ` and call ` containsKey() ` on the
1831
1838
value. If this returns ` false ` , the map does not match.
@@ -1834,7 +1841,7 @@ To match a pattern `p` against a value `v`:
1834
1841
this entry's value subpattern. If it does not match, the map does
1835
1842
not match.
1836
1843
1837
- 3 . The match succeeds if all entry subpatterns match.
1844
+ 4 . The match succeeds if all entry subpatterns match.
1838
1845
1839
1846
* Note that, unlike with lists, a matched map may have additional entries
1840
1847
that are not checked by the pattern.*
@@ -1951,6 +1958,12 @@ Here is one way it could be broken down into separate pieces:
1951
1958
1952
1959
## Changelog
1953
1960
1961
+ ### 2.2
1962
+
1963
+ - Make map patterns check length like list patterns do (#2415 ).
1964
+
1965
+ - Clarify that variables in cases are not final (#2416 ).
1966
+
1954
1967
### 2.1
1955
1968
1956
1969
Minor tweaks:
0 commit comments