Skip to content

Commit 798f3bf

Browse files
committed
allow old syntax when source version < 3.2
1 parent c2854a5 commit 798f3bf

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ object desugar {
521521
val enumCompanionRef = TermRefTree()
522522
val enumImport =
523523
Import(enumCompanionRef, enumCases.flatMap(caseIds).map(
524-
enumCase =>
524+
enumCase =>
525525
ImportSelector(enumCase.withSpan(enumCase.span.startPos))
526-
)
526+
)
527527
)
528528
(enumImport :: enumStats, enumCases, enumCompanionRef)
529529
}
@@ -1134,7 +1134,7 @@ object desugar {
11341134
val matchExpr =
11351135
if (tupleOptimizable) rhs
11361136
else
1137-
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids))
1137+
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids))
11381138
Match(makeSelector(rhs, MatchCheck.IrrefutablePatDef), caseDef :: Nil)
11391139
vars match {
11401140
case Nil if !mods.is(Lazy) =>
@@ -1155,11 +1155,11 @@ object desugar {
11551155
val restDefs =
11561156
for (((named, tpt), n) <- vars.zipWithIndex if named.name != nme.WILDCARD)
11571157
yield
1158-
if mods.is(Lazy) then
1158+
if mods.is(Lazy) then
11591159
DefDef(named.name.asTermName, Nil, tpt, selector(n))
11601160
.withMods(mods &~ Lazy)
11611161
.withSpan(named.span)
1162-
else
1162+
else
11631163
valDef(
11641164
ValDef(named.name.asTermName, tpt, selector(n))
11651165
.withMods(mods)
@@ -1582,7 +1582,7 @@ object desugar {
15821582
if gen.checkMode == GenCheckMode.FilterAlways then // pattern was prefixed by `case`
15831583
false
15841584
else
1585-
gen.checkMode == GenCheckMode.Ignore
1585+
gen.checkMode != GenCheckMode.FilterNow
15861586
|| isVarBinding(gen.pat)
15871587
|| isIrrefutable(gen.pat, gen.expr)
15881588

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
168168
enum GenCheckMode {
169169
case Ignore // neither filter nor check since filtering was done before
170170
case Check // check that pattern is irrefutable
171+
case FilterNow // filter out non-matching elements if we are not in 3.2 or later
171172
case FilterAlways // filter out non-matching elements since pattern is prefixed by `case`
172173
}
173174

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,8 @@ object Parsers {
25162516
atSpan(startOffset(pat), accept(LARROW)) {
25172517
val checkMode =
25182518
if casePat then GenCheckMode.FilterAlways
2519-
else GenCheckMode.Check
2519+
else if sourceVersion.isAtLeast(`3.2`) && !sourceVersion.isMigrating then GenCheckMode.Check
2520+
else GenCheckMode.FilterNow // filter on source version < 3.2, for backward compat
25202521
GenFrom(pat, subExpr(), checkMode)
25212522
}
25222523

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ trait Checking {
814814
def check(pat: Tree, pt: Type): Boolean = (pt <:< pat.tpe) || fail(pat, pt)
815815

816816
def recur(pat: Tree, pt: Type): Boolean =
817+
!(sourceVersion.isAtLeast(`3.2`) && !sourceVersion.isMigrating) ||
817818
pt.hasAnnotation(defn.UncheckedAnnot) || {
818819
patmatch.println(i"check irrefutable $pat: ${pat.tpe} against $pt")
819820
pat match {

0 commit comments

Comments
 (0)