Skip to content

Commit 4ce42eb

Browse files
committed
Move ExpandSAMs to miniphase group before HoistSuperArgs
There are interactions for treating partial functions that require a split into different groups. This move uncovered two follow-on errors which were previously not detected.
1 parent 141bf9e commit 4ce42eb

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
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/transform/ByNameClosures.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class ByNameClosures extends TransformByNameApply with IdentityDenotTransformer
2626

2727
override def phaseName: String = ByNameClosures.name
2828

29+
override def runsAfterGroupsOf: Set[String] = Set(ExpandSAMs.name)
30+
// ExpanSAMs applied to partial functions creates methods that need
31+
// to be fully defined before converting. Test case is pos/i9391.scala.
32+
2933
override def mkByNameClosure(arg: Tree, argType: Type)(using Context): Tree = {
3034
val meth = newSymbol(
3135
ctx.owner, nme.ANON_FUN, Synthetic | Method, MethodType(Nil, Nil, argType))

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)