Skip to content

Commit a30e54b

Browse files
authored
Patch to avoid crash in #16351 (#16354)
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)
2 parents 00c1950 + 49f3ab7 commit a30e54b

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-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 =>
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
val scala3Version = sys.props("plugin.scalaVersion")
2+
val scala2Version = sys.props("plugin.scala2Version")
3+
4+
lazy val lib = project.in(file("lib"))
5+
.settings(
6+
scalaVersion := scala2Version
7+
)
8+
9+
lazy val app = project.in(file("app"))
10+
.dependsOn(lib)
11+
.settings(
12+
scalaVersion := scala3Version
13+
)
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+
)

sbt-test/scala2-compat/i16351/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> app/run

0 commit comments

Comments
 (0)