Skip to content

Patch to avoid crash in #16351 #16354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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