Skip to content

Commit b481090

Browse files
committed
fix rewrites for filtering for generators
the test added here used to fail because the `case` was patched inside the parens, e.g. `for (case x: String) ...` which is not valid
1 parent d82dfcc commit b481090

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1603,7 +1603,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16031603
val isPatDef = checkMode == desugar.MatchCheck.IrrefutablePatDef
16041604
if (!checkIrrefutable(sel, pat, isPatDef) && sourceVersion == `future-migration`)
16051605
if (isPatDef) patch(Span(tree.selector.span.end), ": @unchecked")
1606-
else patch(Span(pat.span.start), "case ")
1606+
else patch(Span(tree.span.start), "case ")
16071607

16081608
// skip exhaustivity check in later phase
16091609
// TODO: move the check above to patternMatcher phase

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class CompilationTests {
7373
aggregateTests(
7474
compileFile("tests/rewrites/rewrites.scala", scala2CompatMode.and("-rewrite", "-indent")),
7575
compileFile("tests/rewrites/rewrites3x.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
76+
compileFile("tests/rewrites/filtering-fors.scala", defaultOptions.and("-rewrite", "-source", "future-migration")),
7677
compileFile("tests/rewrites/i8982.scala", defaultOptions.and("-indent", "-rewrite")),
7778
compileFile("tests/rewrites/i9632.scala", defaultOptions.and("-indent", "-rewrite")),
7879
compileFile("tests/rewrites/i11895.scala", defaultOptions.and("-indent", "-rewrite")),

tests/rewrites/filtering-fors.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
val xs: List[Any] = ???
2+
val as = for case (x: String) <- xs yield x
3+
val bs =
4+
for
5+
case (x: String) <- xs
6+
yield x

tests/rewrites/filtering-fors.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
val xs: List[Any] = ???
2+
val as = for (x: String) <- xs yield x
3+
val bs =
4+
for
5+
(x: String) <- xs
6+
yield x

0 commit comments

Comments
 (0)