Skip to content

Commit a76ea05

Browse files
committed
Move ExpandSAMs to miniphase group before HoistSuperArgs
There are interactions for treating partial functions that require a split into different groups. See pos/i9391.scala for a test case. Also: maintain Extension flags for forwarders. This causes an error in RefChecks for run/fragables-extension.scala otherwise. Previously the error was not detected since methods created in the same group as RefChecks are not checked.
1 parent 141bf9e commit a76ea05

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class Compiler {
6161
new CookComments, // Cook the comments: expand variables, doc, etc.
6262
new CheckStatic, // Check restrictions that apply to @static members
6363
new BetaReduce, // Reduce closure applications
64+
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
6465
new init.Checker) :: // Check initialization of objects
6566
List(new ElimRepeated, // Rewrite vararg parameters and arguments
66-
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
6767
new ProtectedAccessors, // Add accessors for protected members
6868
new ExtensionMethods, // Expand methods of value classes with extension methods
6969
new UncacheGivenAliases, // Avoid caching RHS of simple parameterless given aliases

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
349349
coord = fns.map(_.span).reduceLeft(_ union _))
350350
val constr = newConstructor(cls, Synthetic, Nil, Nil).entered
351351
def forwarder(fn: TermSymbol, name: TermName) = {
352-
val fwdMeth = fn.copy(cls, name, Synthetic | Method | Final).entered.asTerm
352+
val maybeExtension = fn.flags & Extension
353+
val fwdMeth = fn.copy(cls, name, Synthetic | Method | Final | maybeExtension).entered.asTerm
353354
if (fwdMeth.allOverriddenSymbols.exists(!_.is(Deferred))) fwdMeth.setFlag(Override)
354355
polyDefDef(fwdMeth, tprefs => prefss => ref(fn).appliedToTypes(tprefs).appliedToArgss(prefss))
355356
}

compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
4545

4646
def phaseName: String = HoistSuperArgs.name
4747

48+
override def runsAfterGroupsOf: Set[String] = Set(ExpandSAMs.name)
49+
// ExpanSAMs applied to partial functions creates methods that need
50+
// to be fully defined before hoisting. Test case is pos/i9391.scala.
51+
4852
override def runsAfter: Set[String] = Set(ByNameClosures.name)
4953
// By name closures need to be introduced first in order to be hoisted out here.
5054
// There's an interaction with by name closures in that the <cbn-arg> marker

tests/pos/i9391.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def g(x: => Any): Any = x
2+
3+
val a: PartialFunction[Any => Any, Any] = (f => g(f(0)) match { case v => v }) // was an error, now OK

0 commit comments

Comments
 (0)