Skip to content

Commit d8fb65a

Browse files
committed
Fix outer for calling instantiate
1 parent e5cd6fa commit d8fb65a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,9 @@ object Semantic {
629629
// normal method call
630630
if argErrors.nonEmpty && isSyntheticApply(meth) then
631631
val klass = meth.owner.companionClass.asClass
632-
instantiate(klass, klass.primaryConstructor, args, source)
632+
val outerCls = klass.owner.lexicallyEnclosingClass.asClass
633+
val outer = resolveOuterSelect(outerCls, ref, 1, source)
634+
Semantic.instantiate(outer)(klass, klass.primaryConstructor, args, source)
633635
else
634636
withEnv(if isLocal then env else Env.empty) {
635637
eval(ddef.rhs, ref, cls, cacheResult = true) ++ argErrors

tests/init/neg/apply2.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object O:
2+
case class A(b: B):
3+
println(n)
4+
5+
class B:
6+
val a = A(this)
7+
8+
val b = new B
9+
val n = 10 // error
10+
end O

0 commit comments

Comments
 (0)