Skip to content

Commit

Permalink
Patch to avoid crash in #16351 (#16354)
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 #16351  (provisionally)
  • Loading branch information
bishabosha authored Nov 17, 2022
2 parents 00c1950 + 49f3ab7 commit a30e54b
Show file tree
Hide file tree
Showing 5 changed files with 36 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 sbt-test/scala2-compat/i16351/app/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) {}
}
13 changes: 13 additions & 0 deletions sbt-test/scala2-compat/i16351/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
val scala3Version = sys.props("plugin.scalaVersion")
val scala2Version = sys.props("plugin.scala2Version")

lazy val lib = project.in(file("lib"))
.settings(
scalaVersion := scala2Version
)

lazy val app = project.in(file("app"))
.dependsOn(lib)
.settings(
scalaVersion := scala3Version
)
10 changes: 10 additions & 0 deletions sbt-test/scala2-compat/i16351/lib/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
)
1 change: 1 addition & 0 deletions sbt-test/scala2-compat/i16351/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> app/run

0 comments on commit a30e54b

Please sign in to comment.