Skip to content

Commit

Permalink
Patch to avoid crash in #16351
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
odersky committed Nov 16, 2022
1 parent e587a81 commit 1a484de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import collection.mutable
import ast.Trees._
import core.NameKinds.SuperArgName
import SymUtils._
import core.Decorators.*

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

/** Hoist complex arguments in super call out of the class. */
def hoistSuperArgsFromCall(superCall: Tree, cdef: DefDef, lifted: mutable.ListBuffer[Symbol]): Tree = superCall match
case Block(defs, expr) =>
case Block(defs, expr) if !expr.symbol.owner.is(Scala2x) =>
// MO: The guard avoids the crash for #16351.
// It would be good to dig deeper, but I won't have the time myself to do it.
cpy.Block(superCall)(
stats = defs.mapconserve {
case vdef: ValDef =>
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i16351/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package app

import lib.*

object App {
def main(args: Array[String]): Unit =
new Lib(Value("Foo"), b = 2) {}
}
10 changes: 10 additions & 0 deletions tests/pos/i16351/lib.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Should be compiled with 2.13
package lib

class Value(val value: String)

class Lib(
value: => Value,
a: Int = 0,
b: Int
)

0 comments on commit 1a484de

Please sign in to comment.