Skip to content

Commit 1a484de

Browse files
committed
Patch to avoid crash in #16351
This needs follow up but I don't have the time. - figure out why we crash and what is the right fix - fix the test to compile lib with 2.13 Fixes #16531 (provisionally)
1 parent e587a81 commit 1a484de

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import collection.mutable
1313
import ast.Trees._
1414
import core.NameKinds.SuperArgName
1515
import SymUtils._
16+
import core.Decorators.*
1617

1718
object HoistSuperArgs {
1819
val name: String = "hoistSuperArgs"
@@ -181,7 +182,9 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
181182

182183
/** Hoist complex arguments in super call out of the class. */
183184
def hoistSuperArgsFromCall(superCall: Tree, cdef: DefDef, lifted: mutable.ListBuffer[Symbol]): Tree = superCall match
184-
case Block(defs, expr) =>
185+
case Block(defs, expr) if !expr.symbol.owner.is(Scala2x) =>
186+
// MO: The guard avoids the crash for #16351.
187+
// It would be good to dig deeper, but I won't have the time myself to do it.
185188
cpy.Block(superCall)(
186189
stats = defs.mapconserve {
187190
case vdef: ValDef =>

tests/pos/i16351/App.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package app
2+
3+
import lib.*
4+
5+
object App {
6+
def main(args: Array[String]): Unit =
7+
new Lib(Value("Foo"), b = 2) {}
8+
}

tests/pos/i16351/lib.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Should be compiled with 2.13
2+
package lib
3+
4+
class Value(val value: String)
5+
6+
class Lib(
7+
value: => Value,
8+
a: Int = 0,
9+
b: Int
10+
)

0 commit comments

Comments
 (0)