From 1a484de2c9b5ffde6411542cfbc20fe7579ba6bc Mon Sep 17 00:00:00 2001 From: odersky Date: Wed, 16 Nov 2022 21:44:03 +0100 Subject: [PATCH] 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 +)