Skip to content

Commit 5c808a1

Browse files
authored
[patterns] Correct how patterns are lifted to spaces. (#2688)
Fix #2681.
1 parent b30c50b commit 5c808a1

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

accepted/future-releases/0546-patterns/exhaustiveness.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ into spaces:
385385
* **Variable pattern:** An object space whose type is the variable's type
386386
(which might be inferred).
387387
388-
* **Literal or constant matcher:** These are handled specially depending on
388+
* **Literal or constant pattern:** These are handled specially depending on
389389
the constant's type:
390390
391391
* We treat `bool` like a sealed supertype with subtypes `true` and
@@ -426,10 +426,15 @@ into spaces:
426426
the same string constant. Also the switch has a non-exhaustive error
427427
since it doesn't match the entire `String` type.
428428
429-
* **Null-check matcher:** An object space whose type is the underlying
430-
non-nullable type of the pattern. It contains a single field, `this` that
431-
returns the same value it is called on. That field's space is the lifted
432-
subpattern of the null-check pattern. For example:
429+
* **Object pattern:** An object space whose type is the object pattern's type
430+
and whose fields are the lifted fields of the object pattern. Positional
431+
fields in the object pattern get implicit names like `field0`, `field1`,
432+
etc.
433+
434+
* **Null-check pattern:** An object space whose type is the non-nullable
435+
underlying type of the pattern's matched value type. It contains a single
436+
field, `this` that returns the same value it is called on. That field's
437+
space is the lifted subpattern of the null-check pattern. For example:
433438
434439
```dart
435440
Card? card;
@@ -444,16 +449,15 @@ into spaces:
444449
Card(this: Jack(oneEyed: true))
445450
```
446451
447-
* **Object pattern:** An object space whose type is the object pattern's type
448-
and whose fields are the lifted fields of the object pattern. Positional
449-
fields in the object pattern get implicit names like `field0`, `field1`,
450-
etc.
451-
452-
* **Null-assert or cast binder:** An object space of type `top`.
452+
* **Null-assert pattern:** The union of the lifted space of `null` and the
453+
lifted space of the subpattern.
453454
455+
* **Cast pattern:** The space `(matched - cast) | subpattern` where `matched`
456+
is the lifted space of the matched value type for this pattern, `cast` is
457+
the lifted space for the type being cast to, and `subpattern` is the lifted
458+
space for the subpattern.
454459
455-
**TODO: Once generics are supported, describe how type patterns are lifted to
456-
spaces here.**
460+
**TODO: Once generics are supported, describe how type arguments work.**
457461
458462
## The algorithm
459463

0 commit comments

Comments
 (0)