Commit 675a43b
authored
Fix irrefutability checking in
Before this PR, the two for comprehensions in the added test case
behaved differently:
```scala
-- Error: tests/neg/irrefutable-genfrom.scala:5:10 -----------------------------
5 | (i, Some(_)) <- List.empty[Int] zip List.empty[Option[String]] // error
| ^^^^^^^
|pattern's type Some[String] is more specialized than the right hand side expression's type Option[String]
|
|If the narrowing is intentional, this can be communicated by adding the `case` keyword before the full pattern,
|which will result in a filtering for expression (using `withFilter`).
|This patch can be rewritten automatically under -rewrite -source 3.2-migration.
-- Warning: tests/neg/irrefutable-genfrom.scala:11:6 ---------------------------
11 | (i, Some(_)) <- List.empty[Int] lazyZip List.empty[Option[String]] // error
| ^
|pattern's type Some[String] is more specialized than the right hand side expression's type Option[String]
|
|If the narrowing is intentional, this can be communicated by adding `: @unchecked` after the expression,
|which may result in a MatchError at runtime.
|This patch can be rewritten automatically under -rewrite -source 3.2-migration.
```
The second one was incorrect: just like the first one, we should use the
`case` keyword to make the pattern partial since we're in a for
comprehension, but this information was lost when calling
`makeCaseLambda` in `typedFunctionValue`. To fix this, we need to
retrieve the attachment in the scrutinee (it was added there by
`makeSelector` called from `makeCaseLambda` called from `makeLambda`
called from `makeFor` in `Desugar.scala`).for with untupling (#23273)1 parent 606268f commit 675a43b
File tree
2 files changed
+15
-1
lines changed- compiler/src/dotty/tools/dotc/typer
- tests/neg
2 files changed
+15
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1938 | 1938 | | |
1939 | 1939 | | |
1940 | 1940 | | |
| 1941 | + | |
| 1942 | + | |
1941 | 1943 | | |
1942 | 1944 | | |
1943 | | - | |
| 1945 | + | |
1944 | 1946 | | |
1945 | 1947 | | |
1946 | 1948 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments