Skip to content

Commit 42d69ab

Browse files
authored
Merge pull request scala#7260 from retronym/topic/postpone-patmat
Defer the pattern matching phase until after refchecks
2 parents 3b63ee9 + 6892e2f commit 42d69ab

File tree

11 files changed

+46
-66
lines changed

11 files changed

+46
-66
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -466,16 +466,6 @@ class Global(var currentSettings: Settings, reporter0: LegacyReporter)
466466
if (settings.YmacroAnnotations) new { val global: Global.this.type = Global.this } with Analyzer with MacroAnnotationNamers
467467
else new { val global: Global.this.type = Global.this } with Analyzer
468468

469-
// phaseName = "patmat"
470-
object patmat extends {
471-
val global: Global.this.type = Global.this
472-
// patmat does not need to run before the superaccessors phase, because
473-
// patmat never emits `this.x` where `x` is a ParamAccessor.
474-
// (However, patmat does need to run before outer accessors generation).
475-
val runsAfter = List("superaccessors")
476-
val runsRightAfter = None
477-
} with PatternMatching
478-
479469
// phaseName = "superaccessors"
480470
object superAccessors extends {
481471
val global: Global.this.type = Global.this
@@ -487,7 +477,7 @@ class Global(var currentSettings: Settings, reporter0: LegacyReporter)
487477
// phaseName = "extmethods"
488478
object extensionMethods extends {
489479
val global: Global.this.type = Global.this
490-
val runsAfter = List("patmat")
480+
val runsAfter = List("superaccessors")
491481
val runsRightAfter = None
492482
} with ExtensionMethods
493483

@@ -505,10 +495,20 @@ class Global(var currentSettings: Settings, reporter0: LegacyReporter)
505495
val runsRightAfter = None
506496
} with RefChecks
507497

498+
// phaseName = "patmat"
499+
object patmat extends {
500+
val global: Global.this.type = Global.this
501+
// patmat does not need to run before the superaccessors phase, because
502+
// patmat never emits `this.x` where `x` is a ParamAccessor.
503+
// (However, patmat does need to run before outer accessors generation).
504+
val runsAfter = List("refchecks")
505+
val runsRightAfter = None
506+
} with PatternMatching
507+
508508
// phaseName = "uncurry"
509509
override object uncurry extends {
510510
val global: Global.this.type = Global.this
511-
val runsAfter = List("refchecks")
511+
val runsAfter = List("patmat")
512512
val runsRightAfter = None
513513
} with UnCurry
514514

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,26 +1822,6 @@ abstract class RefChecks extends Transform {
18221822
transform(pat)
18231823
}
18241824
treeCopy.CaseDef(tree, pat1, transform(guard), transform(body))
1825-
case LabelDef(_, _, _) if treeInfo.hasSynthCaseSymbol(result) =>
1826-
savingInPattern {
1827-
inPattern = true
1828-
deriveLabelDef(result)(transform)
1829-
}
1830-
case Apply(fun, args) if fun.symbol.isLabel && treeInfo.isSynthCaseSymbol(fun.symbol) =>
1831-
savingInPattern {
1832-
// scala/bug#7756 If we were in a translated pattern, we can now switch out of pattern mode, as the label apply signals
1833-
// that we are in the user-supplied code in the case body.
1834-
//
1835-
// Relies on the translation of:
1836-
// (null: Any) match { case x: List[_] => x; x.reverse; case _ => }'
1837-
// to:
1838-
// <synthetic> val x2: List[_] = (x1.asInstanceOf[List[_]]: List[_]);
1839-
// matchEnd4({ x2; x2.reverse}) // case body is an argument to a label apply.
1840-
inPattern = false
1841-
super.transform(result)
1842-
}
1843-
case ValDef(_, _, _, _) if treeInfo.hasSynthCaseSymbol(result) =>
1844-
deriveValDef(result)(transform) // scala/bug#7716 Don't refcheck the tpt of the synthetic val that holds the selector.
18451825
case _ =>
18461826
result.transform(this)
18471827
}

test/files/neg/t6446-additional.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
packageobjects 3 load package objects
66
typer 4 the meat and potatoes: type the trees
77
superaccessors 5 add super accessors in traits and nested classes
8-
patmat 6 translate match expressions
9-
extmethods 7 add extension methods for inline classes
10-
pickler 8 serialize symbol tables
11-
refchecks 9 reference/override checking, translate nested objects
8+
extmethods 6 add extension methods for inline classes
9+
pickler 7 serialize symbol tables
10+
refchecks 8 reference/override checking, translate nested objects
11+
patmat 9 translate match expressions
1212
uncurry 10 uncurry, translate function values to anonymous classes
1313
fields 11 synthesize accessors and fields, add bitmaps for lazy vals
1414
tailcalls 12 replace tail calls by jumps

test/files/neg/t6446-missing.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Error: unable to load class: t6446.Ploogin
66
packageobjects 3 load package objects
77
typer 4 the meat and potatoes: type the trees
88
superaccessors 5 add super accessors in traits and nested classes
9-
patmat 6 translate match expressions
10-
extmethods 7 add extension methods for inline classes
11-
pickler 8 serialize symbol tables
12-
refchecks 9 reference/override checking, translate nested objects
9+
extmethods 6 add extension methods for inline classes
10+
pickler 7 serialize symbol tables
11+
refchecks 8 reference/override checking, translate nested objects
12+
patmat 9 translate match expressions
1313
uncurry 10 uncurry, translate function values to anonymous classes
1414
fields 11 synthesize accessors and fields, add bitmaps for lazy vals
1515
tailcalls 12 replace tail calls by jumps

test/files/neg/t6446-show-phases.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
packageobjects 3 load package objects
66
typer 4 the meat and potatoes: type the trees
77
superaccessors 5 add super accessors in traits and nested classes
8-
patmat 6 translate match expressions
9-
extmethods 7 add extension methods for inline classes
10-
pickler 8 serialize symbol tables
11-
refchecks 9 reference/override checking, translate nested objects
8+
extmethods 6 add extension methods for inline classes
9+
pickler 7 serialize symbol tables
10+
refchecks 8 reference/override checking, translate nested objects
11+
patmat 9 translate match expressions
1212
uncurry 10 uncurry, translate function values to anonymous classes
1313
fields 11 synthesize accessors and fields, add bitmaps for lazy vals
1414
tailcalls 12 replace tail calls by jumps

test/files/neg/t7494-no-options.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ error: Error: ploogin takes no options
66
packageobjects 3 load package objects
77
typer 4 the meat and potatoes: type the trees
88
superaccessors 5 add super accessors in traits and nested classes
9-
patmat 6 translate match expressions
10-
extmethods 7 add extension methods for inline classes
11-
pickler 8 serialize symbol tables
12-
refchecks 9 reference/override checking, translate nested objects
9+
extmethods 6 add extension methods for inline classes
10+
pickler 7 serialize symbol tables
11+
refchecks 8 reference/override checking, translate nested objects
12+
patmat 9 translate match expressions
1313
uncurry 10 uncurry, translate function values to anonymous classes
1414
fields 11 synthesize accessors and fields, add bitmaps for lazy vals
1515
tailcalls 12 replace tail calls by jumps

test/files/run/patmat-seq.check

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package <empty> {
1515
B.super.<init>();
1616
()
1717
};
18-
def unapplySeq(a: Int): Some[scala.collection.immutable.ArraySeq[Int]] = scala.Some.apply[scala.collection.immutable.ArraySeq[Int]](scala.collection.immutable.ArraySeq.apply[Int](1, 2, 3)((ClassTag.Int: scala.reflect.ClassTag[Int])))
18+
def unapplySeq(a: Int): Some[scala.collection.immutable.ArraySeq[Int]] = new Some[scala.collection.immutable.ArraySeq[Int]](scala.collection.immutable.ArraySeq.apply[Int](1, 2, 3)((ClassTag.Int: scala.reflect.ClassTag[Int])))
1919
};
2020
class Foo[T] extends scala.AnyRef {
2121
def <init>(): Foo[T] = {
@@ -41,7 +41,7 @@ package <empty> {
4141
D.super.<init>();
4242
()
4343
};
44-
def unapplySeq[T](a: Int): Some[Foo[T]] = scala.Some.apply[Foo[T]](new Foo[T]())
44+
def unapplySeq[T](a: Int): Some[Foo[T]] = new Some[Foo[T]](new Foo[T]())
4545
};
4646
object E extends scala.AnyRef {
4747
def <init>(): E.type = {
@@ -55,7 +55,7 @@ package <empty> {
5555
F.super.<init>();
5656
()
5757
};
58-
def unapplySeq(a: Int): Some[String] = scala.Some.apply[String]("123")
58+
def unapplySeq(a: Int): Some[String] = new Some[String]("123")
5959
};
6060
class T extends scala.AnyRef {
6161
def <init>(): T = {
@@ -80,7 +80,7 @@ package <empty> {
8080
{
8181
val x: Int = o20.get.apply(0);
8282
val y: Int = o20.get.apply(1);
83-
matchEnd15(scala.Tuple2.apply[Int, Int](x, y))
83+
matchEnd15(new (Int, Int)(x, y))
8484
}
8585
else
8686
case19()
@@ -91,7 +91,7 @@ package <empty> {
9191
{
9292
val x: Int = o22.get.apply(0);
9393
val xs: Seq[Int] = o22.get.drop(1);
94-
matchEnd15(scala.Tuple2.apply[Int, Seq[Int]](x, xs))
94+
matchEnd15(new (Int, Seq[Int])(x, xs))
9595
}
9696
else
9797
case21()
@@ -112,7 +112,7 @@ package <empty> {
112112
{
113113
val x: Int = o26.get.apply(0);
114114
val y: Int = o26.get.apply(1);
115-
matchEnd15(scala.Tuple2.apply[Int, Int](x, y))
115+
matchEnd15(new (Int, Int)(x, y))
116116
}
117117
else
118118
case25()
@@ -123,7 +123,7 @@ package <empty> {
123123
{
124124
val x: Int = o28.get.apply(0);
125125
val xs: Seq[Int] = o28.get.drop(1);
126-
matchEnd15(scala.Tuple2.apply[Int, Seq[Int]](x, xs))
126+
matchEnd15(new (Int, Seq[Int])(x, xs))
127127
}
128128
else
129129
case27()
@@ -144,7 +144,7 @@ package <empty> {
144144
{
145145
val x: Int = o32.get.apply(0);
146146
val y: Int = o32.get.apply(1);
147-
matchEnd15(scala.Tuple2.apply[Int, Int](x, y))
147+
matchEnd15(new (Int, Int)(x, y))
148148
}
149149
else
150150
case31()
@@ -155,7 +155,7 @@ package <empty> {
155155
{
156156
val x: Int = o34.get.apply(0);
157157
val xs: Seq[Int] = o34.get.drop(1);
158-
matchEnd15(scala.Tuple2.apply[Int, Seq[Int]](x, xs))
158+
matchEnd15(new (Int, Seq[Int])(x, xs))
159159
}
160160
else
161161
case33()
@@ -176,7 +176,7 @@ package <empty> {
176176
{
177177
val x: Nothing = o38.get.apply(0);
178178
val y: Nothing = o38.get.apply(1);
179-
matchEnd15(scala.Tuple2.apply[Nothing, Nothing](x, y))
179+
matchEnd15(new (Nothing, Nothing)(x, y))
180180
}
181181
else
182182
case37()
@@ -187,7 +187,7 @@ package <empty> {
187187
{
188188
val x: Nothing = o40.get.apply(0);
189189
val xs: Seq[Nothing] = o40.get.drop(1);
190-
matchEnd15(scala.Tuple2.apply[Nothing, Seq[Nothing]](x, xs))
190+
matchEnd15(new (Nothing, Seq[Nothing])(x, xs))
191191
}
192192
else
193193
case39()

test/files/run/programmatic-main.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
packageobjects 3 load package objects
66
typer 4 the meat and potatoes: type the trees
77
superaccessors 5 add super accessors in traits and nested classes
8-
patmat 6 translate match expressions
9-
extmethods 7 add extension methods for inline classes
10-
pickler 8 serialize symbol tables
11-
refchecks 9 reference/override checking, translate nested objects
8+
extmethods 6 add extension methods for inline classes
9+
pickler 7 serialize symbol tables
10+
refchecks 8 reference/override checking, translate nested objects
11+
patmat 9 translate match expressions
1212
uncurry 10 uncurry, translate function values to anonymous classes
1313
fields 11 synthesize accessors and fields, add bitmaps for lazy vals
1414
tailcalls 12 replace tail calls by jumps

test/files/run/t1434.check

Whitespace-only changes.

test/files/run/t1434.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object Test {
2-
class A[T] { val op = null }
2+
class A[T] { val op: AnyRef = null }
33
class B extends A[Any]
44
class C extends B
55

test/files/run/t6288.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[106][106][106]Case3.super.<init>();
66
[13]()
77
};
8-
[21]def unapply([29]z: [32]<type: [32]scala.Any>): [21]Option[Int] = [56][52][52]scala.Some.apply[[52]Int]([57]-1);
8+
[21]def unapply([29]z: [32]<type: [32]scala.Any>): [21]Option[Int] = [56][52][52]new [52]Some[Int]([57]-1);
99
[64]{
1010
[64]case <synthetic> val x1: [64]String = [64]"";
1111
[64]case5(){
@@ -89,7 +89,7 @@
8989
[417][417][417]Case6.super.<init>();
9090
[326]()
9191
};
92-
[334]def unapply([342]z: [345]<type: [345]scala.Int>): [334]Option[Int] = [369][365][365]scala.Some.apply[[365]Int]([370]-1);
92+
[334]def unapply([342]z: [345]<type: [345]scala.Int>): [334]Option[Int] = [369][365][365]new [365]Some[Int]([370]-1);
9393
[377]{
9494
[377]case <synthetic> val x1: [377]Int = [377]0;
9595
[377]case5()[396]{

0 commit comments

Comments
 (0)