From 1a484de2c9b5ffde6411542cfbc20fe7579ba6bc Mon Sep 17 00:00:00 2001 From: odersky Date: Wed, 16 Nov 2022 21:44:03 +0100 Subject: [PATCH 1/2] 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) --- .../dotty/tools/dotc/transform/HoistSuperArgs.scala | 5 ++++- tests/pos/i16351/App.scala | 8 ++++++++ tests/pos/i16351/lib.scala | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i16351/App.scala create mode 100644 tests/pos/i16351/lib.scala diff --git a/compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala b/compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala index edbfbd1552c4..9a36d65babe8 100644 --- a/compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala +++ b/compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala @@ -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" @@ -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 => diff --git a/tests/pos/i16351/App.scala b/tests/pos/i16351/App.scala new file mode 100644 index 000000000000..5c152f515ada --- /dev/null +++ b/tests/pos/i16351/App.scala @@ -0,0 +1,8 @@ +package app + +import lib.* + +object App { + def main(args: Array[String]): Unit = + new Lib(Value("Foo"), b = 2) {} +} diff --git a/tests/pos/i16351/lib.scala b/tests/pos/i16351/lib.scala new file mode 100644 index 000000000000..cfc3c6c780d9 --- /dev/null +++ b/tests/pos/i16351/lib.scala @@ -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 +) From 49f3ab77b17e9d6a4872276e08596e036ef97315 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Thu, 17 Nov 2022 11:51:17 +0100 Subject: [PATCH 2/2] move scala 2 test to sbt-test --- .../scala2-compat/i16351/app}/App.scala | 0 sbt-test/scala2-compat/i16351/build.sbt | 13 +++++++++++++ .../scala2-compat/i16351/lib}/lib.scala | 0 sbt-test/scala2-compat/i16351/test | 1 + 4 files changed, 14 insertions(+) rename {tests/pos/i16351 => sbt-test/scala2-compat/i16351/app}/App.scala (100%) create mode 100644 sbt-test/scala2-compat/i16351/build.sbt rename {tests/pos/i16351 => sbt-test/scala2-compat/i16351/lib}/lib.scala (100%) create mode 100644 sbt-test/scala2-compat/i16351/test diff --git a/tests/pos/i16351/App.scala b/sbt-test/scala2-compat/i16351/app/App.scala similarity index 100% rename from tests/pos/i16351/App.scala rename to sbt-test/scala2-compat/i16351/app/App.scala diff --git a/sbt-test/scala2-compat/i16351/build.sbt b/sbt-test/scala2-compat/i16351/build.sbt new file mode 100644 index 000000000000..433a5e8baddf --- /dev/null +++ b/sbt-test/scala2-compat/i16351/build.sbt @@ -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 + ) diff --git a/tests/pos/i16351/lib.scala b/sbt-test/scala2-compat/i16351/lib/lib.scala similarity index 100% rename from tests/pos/i16351/lib.scala rename to sbt-test/scala2-compat/i16351/lib/lib.scala diff --git a/sbt-test/scala2-compat/i16351/test b/sbt-test/scala2-compat/i16351/test new file mode 100644 index 000000000000..63092ffa4a03 --- /dev/null +++ b/sbt-test/scala2-compat/i16351/test @@ -0,0 +1 @@ +> app/run