Skip to content

Commit d057f13

Browse files
committed
TypeAssigner#avoid: preserve type parameters if possible
We need to use `baseTypeWithArgs` to replace `Bar` by its supertype `Foo` in the type `Bar[Int]`. Fixes scala#741.
1 parent 55389ea commit d057f13

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ trait TypeAssigner {
8888
case _ =>
8989
mapOver(tp)
9090
}
91-
case tp: RefinedType =>
92-
val tp1 @ RefinedType(parent1, _) = mapOver(tp)
93-
if (tp1.refinedInfo.existsPart(toAvoid) && variance > 0) {
94-
typr.println(s"dropping refinement from $tp1")
91+
case tp: RefinedType if variance > 0 =>
92+
val parent1 = apply(tp.parent)
93+
if (tp.refinedInfo.existsPart(toAvoid)) {
94+
typr.println(s"dropping refinement from $tp")
9595
parent1
96-
}
97-
else tp1
96+
} else if (parent1 != tp.parent) {
97+
tp.baseTypeWithArgs(parent1.classSymbol)
98+
} else
99+
tp
98100
case tp: TypeVar if ctx.typerState.constraint.contains(tp) =>
99101
val lo = ctx.typerState.constraint.fullLowerBound(tp.origin)
100102
val lo1 = avoid(lo, symsToAvoid)

tests/pos/escapingRefs.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
class Foo[A]
2+
13
class Outer {
24
class Inner
35
}
@@ -8,5 +10,10 @@ object Test {
810
val o = new Outer
911
new o.Inner
1012
}
13+
14+
val b = {
15+
class Bar[B] extends Foo[B]
16+
new Bar[Int]
17+
}
1118
}
1219
}

0 commit comments

Comments
 (0)