Skip to content

Commit 144546d

Browse files
committed
Fix #1990: Handle case where inlining changes class of outer
The new situation in the test was that outer of the inlined method was `A` but it's as seen from type is a subtype `B`. Outer path logic can't handle that, so we widen back to an A instance with `baseTypeWithArgs`.
1 parent 6df672c commit 144546d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import core.Types._
1212
import core.Flags._
1313
import core.Constants._
1414
import core.StdNames._
15+
import core.NameOps._
1516
import core.Decorators._
1617
import core.TypeErasure.isErasedType
1718
import core.Phases.Phase
@@ -336,7 +337,9 @@ class TreeChecker extends Phase with SymTransformer {
336337
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
337338
val tpe = tree.typeOpt
338339
val sym = tree.symbol
339-
if (!tpe.isInstanceOf[WithFixedSym] && sym.exists && !sym.is(Private)) {
340+
if (!tpe.isInstanceOf[WithFixedSym] &&
341+
sym.exists && !sym.is(Private) &&
342+
!tree.name.isOuterSelect // outer selects have effectively fixed symbols) {
340343
val qualTpe = tree.qualifier.typeOpt
341344
val member =
342345
if (sym.is(Private)) qualTpe.member(tree.name)

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
367367
else {
368368
val proxyName = s"${tpe.cls.name}_this".toTermName
369369
val proxyType = tpe.asSeenFrom(prefix.tpe, meth.owner)
370+
.baseTypeWithArgs(tpe.cls) // outer path logic requires that the proxy has the same class as the original this type
370371
thisProxy(tpe.cls) = newSym(proxyName, EmptyFlags, proxyType).termRef
371372
registerType(meth.owner.thisType) // make sure we have a base from which to outer-select
372373
}

tests/pos/i1990.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class A {
2+
class Foo {
3+
inline def inlineMeth: Unit = {
4+
new Bar
5+
}
6+
}
7+
class Bar
8+
}
9+
10+
class B extends A {
11+
(new Foo).inlineMeth
12+
}

0 commit comments

Comments
 (0)