Skip to content
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
9 changes: 8 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Constructors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,16 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
// (2) If the parameter accessor reference was to an alias getter,
// drop the () when replacing by the parameter.
object intoConstr extends TreeMap {
private var isSuperCall = false
override def transform(tree: Tree)(using Context): Tree = tree match {
case Ident(_) | Select(This(_), _) =>
var sym = tree.symbol
if (sym.is(ParamAccessor, butNot = Mutable)) sym = sym.subst(accessors, paramSyms)
if sym.is(ParamAccessor) && (!sym.is(Mutable) || isSuperCall)
// Variables need to go through the getter since they might have been updated,
// except if we are in a super call, since then the virtual getter call would
// be illegal.
then
sym = sym.subst(accessors, paramSyms)
if (sym.maybeOwner.isConstructor) ref(sym).withSpan(tree.span) else tree
case Apply(fn, Nil) =>
val fn1 = transform(fn)
Expand All @@ -161,6 +167,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase =
}

def apply(tree: Tree, prevOwner: Symbol)(using Context): Tree =
isSuperCall = isSuperConstrCall(tree)
transform(tree).changeOwnerAfter(prevOwner, constr.symbol, thisPhase)
}

Expand Down
5 changes: 0 additions & 5 deletions tests/neg/i11045.scala

This file was deleted.

5 changes: 5 additions & 0 deletions tests/run/i11045.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abstract class Foo(x: Any)
class Boom(var x: Unit, y: Unit) extends Foo((x: Int) => x) // was error: super constructor cannot be passed a self reference
@main def Test =
Boom((), ())

1 change: 1 addition & 0 deletions tests/run/i13630.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
it worked
9 changes: 9 additions & 0 deletions tests/run/i13630.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ClassWithLambda(sup: () => Long)
class ClassWithVar(var msg: String) extends ClassWithLambda(() => 1)

object Test:
val _ = new ClassWithVar("foo")

def main(args: Array[String]): Unit = {
println("it worked")
}