Skip to content

Commit 3422f54

Browse files
[Patterns] remove irrelevant specification of pattern type schemas. (#2639)
The pattern type schemas for logical-or, null-check, constant, and relational patterns were not meaningful because pattern type schemas are only used in refutable contexts, and these patterns are not allowed to appear in irrefutable contexts. In particular, the definition of pattern type schema for constant patterns was causing confusion because it appeared to cause a circularity: it defined the pattern type schema for a constant pattern to be the inferred type of the constant; however text elsewhere specifies that the type of the constant is inferred based on the type of the scrutinee, and the pattern type schema is used to infer the type of the scrutinee. However this wasn't a real problem, because constant patterns are illegal in precisely the circumstances in whch pattern type schemas are used.
1 parent f06d416 commit 3422f54

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

accepted/future-releases/0546-patterns/feature-specification.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,22 +1570,16 @@ var (a, int b) = ... // Schema is `(?, int)`.
15701570

15711571
The context type schema for a pattern `p` is:
15721572

1573-
* **Logical-or**: The least upper bound of the context type schemas of the
1574-
branches.
1575-
15761573
* **Logical-and**: The greatest lower bound of the context type schemas of the
15771574
branches.
15781575

1579-
* **Null-check** or **null-assert**: A context type schema `E?` where `E` is
1580-
the context type schema of the inner pattern. *For example:*
1576+
* **Null-assert**: A context type schema `E?` where `E` is the context type
1577+
schema of the inner pattern. *For example:*
15811578

15821579
```dart
15831580
var [[int x]!] = [[]]; // Infers List<List<int>?> for the list literal.
15841581
```
15851582
1586-
* **Constant**: The context type schema is the static type of the pattern's
1587-
value.
1588-
15891583
* **Variable**:
15901584
15911585
1. In an assignment context, the context type schema is the static type of
@@ -1604,7 +1598,7 @@ The context type schema for a pattern `p` is:
16041598
// ^- Infers List<int>.
16051599
```
16061600
1607-
* **Relational** or **cast**: The context type schema is `?`.
1601+
* **Cast**: The context type schema is `?`.
16081602
16091603
* **Parenthesized**: The context type schema of the inner subpattern.
16101604
@@ -1675,6 +1669,10 @@ The context type schema for a pattern `p` is:
16751669
// ^-- Infer Foo<num>.
16761670
```
16771671
1672+
The pattern type schema for logical-or, null-check, constant, and relational
1673+
patterns is not defined, because those patterns are only allowed in refutable
1674+
contexts, and the pattern type schema is only used in irrefutable contexts.
1675+
16781676
#### Type checking and pattern required type
16791677
16801678
Once the value a pattern is matched against has a static type (which means

0 commit comments

Comments
 (0)