Skip to content

Commit 7f60d2f

Browse files
committed
Preserve FilterAlways in withFilter
1 parent bb5c8b3 commit 7f60d2f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,18 +1439,13 @@ object desugar {
14391439
* IrrefutableGenFrom: sel with attachment `CheckIrrefutable -> checkMode`
14401440
*/
14411441
def makeSelector(sel: Tree, checkMode: MatchCheck)(using Context): Tree =
1442+
import MatchCheck.*
14421443
checkMode match
1443-
case MatchCheck.None =>
1444-
Annotated(sel, New(ref(defn.UncheckedAnnot.typeRef)))
1445-
1446-
case MatchCheck.Exhaustive =>
1447-
sel
1448-
1449-
case MatchCheck.IrrefutablePatDef | MatchCheck.IrrefutableGenFrom =>
1444+
case None => Annotated(sel, New(ref(defn.UncheckedAnnot.typeRef)))
1445+
case Exhaustive => sel
1446+
case IrrefutablePatDef
1447+
| IrrefutableGenFrom => sel.withAttachment(CheckIrrefutable, checkMode)
14501448
// TODO: use `pushAttachment` and investigate duplicate attachment
1451-
sel.withAttachment(CheckIrrefutable, checkMode)
1452-
sel
1453-
end match
14541449

14551450
case class TuplePatternInfo(arity: Int, varNum: Int, wildcardNum: Int)
14561451
object TuplePatternInfo:
@@ -2284,7 +2279,12 @@ object desugar {
22842279
case (gen: GenFrom) :: test :: rest =>
22852280
val genFrom =
22862281
val filtered = Apply(rhsSelect(gen, nme.withFilter), makeLambda(gen, test))
2287-
val mode = if sourceVersion.enablesBetterFors then GenCheckMode.Filtered else GenCheckMode.Ignore
2282+
val mode =
2283+
import GenCheckMode.*
2284+
if sourceVersion.enablesBetterFors then
2285+
if gen.checkMode eq FilterAlways then FilterAlways
2286+
else Filtered
2287+
else Ignore
22882288
GenFrom(gen.pat, filtered, mode)
22892289
makeFor(mapName, flatMapName, genFrom :: rest, body)
22902290
case enums @ GenAlias(_, _) :: _ if sourceVersion.enablesBetterFors =>

tests/neg/filtering-fors.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ object Test {
3131
for (case (x: String) <- xs; case (y, z) <- xs) do () // OK
3232

3333
for (case (x, y) <- pairs) yield (y, x) // OK
34+
35+
for case x: String <- xs if x.length < 5 yield x // OK
3436
}

0 commit comments

Comments
 (0)