Skip to content

Commit afbc529

Browse files
committed
Map parents of ClassInfos when inlining
Otherwise base tyeps of inlined classes are wrong.
1 parent d46a5b9 commit afbc529

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final class TreeTypeMap(
8080
val tmap = withMappedSyms(localSyms(impl :: self :: Nil))
8181
cpy.Template(impl)(
8282
constr = tmap.transformSub(constr),
83-
parents = parents mapconserve transform,
83+
parents = parents.mapconserve(transform),
8484
self = tmap.transformSub(self),
8585
body = impl.body mapconserve
8686
(tmap.transform(_)(ctx.withOwner(mapOwner(impl.symbol.owner))))

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,6 +3850,17 @@ object Types {
38503850
protected def mapClassInfo(tp: ClassInfo): Type =
38513851
derivedClassInfo(tp, this(tp.prefix))
38523852

3853+
/** A version of mapClassInfo which also maps parents and self type */
3854+
protected def mapFullClassInfo(tp: ClassInfo) =
3855+
tp.derivedClassInfo(
3856+
prefix = this(tp.prefix),
3857+
classParents = tp.classParents.mapConserve(this),
3858+
selfInfo = tp.selfInfo match {
3859+
case tp: Type => this(tp)
3860+
case sym => sym
3861+
}
3862+
)
3863+
38533864
def andThen(f: Type => Type): TypeMap = new TypeMap {
38543865
override def stopAtStatic = thisMap.stopAtStatic
38553866
def apply(tp: Type) = f(thisMap(tp))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
446446
case t: SingletonType => paramProxy.getOrElse(t, mapOver(t))
447447
case t => mapOver(t)
448448
}
449+
override def mapClassInfo(tp: ClassInfo) = mapFullClassInfo(tp)
449450
}
450451

451452
// The tree map to apply to the inlined tree. This maps references to this-types

tests/pos/i3130b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
trait F { def f(): Int }
21
class Outer {
2+
trait F { def f(): Int }
33
inline def inner: F = {
44
class InnerClass(x: Int) extends F {
55
def this() = this(3)

0 commit comments

Comments
 (0)