Skip to content

Commit 2dfc585

Browse files
committed
TypeAssigner#avoid: don't miss escaping refs in complex types
1 parent 35e6553 commit 2dfc585

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,17 @@ trait TypeAssigner {
4040
def avoid(tp: Type, symsToAvoid: => List[Symbol])(implicit ctx: Context): Type = {
4141
val widenMap = new TypeMap {
4242
lazy val forbidden = symsToAvoid.toSet
43-
def toAvoid(tp: Type): Boolean = tp match {
44-
case tp: TermRef =>
45-
val sym = tp.symbol
46-
sym.exists && (
47-
sym.owner.isTerm && (forbidden contains sym)
48-
|| !(sym.owner is Package) && toAvoid(tp.prefix)
49-
)
50-
case tp: TypeRef =>
51-
forbidden contains tp.symbol
52-
case _ =>
53-
false
54-
}
43+
def toAvoid(tp: Type): Boolean =
44+
tp existsPart {
45+
case tp: NamedType =>
46+
forbidden contains tp.symbol
47+
case _ =>
48+
false
49+
}
5550
def apply(tp: Type): Type = tp match {
5651
case tp: TermRef if toAvoid(tp) && variance > 0 =>
5752
apply(tp.info.widenExpr)
58-
case tp: TypeRef if (forbidden contains tp.symbol) || toAvoid(tp.prefix) =>
53+
case tp: TypeRef if toAvoid(tp) =>
5954
tp.info match {
6055
case TypeAlias(ref) =>
6156
apply(ref)
@@ -90,7 +85,7 @@ trait TypeAssigner {
9085
}
9186
case tp: RefinedType =>
9287
val tp1 @ RefinedType(parent1, _) = mapOver(tp)
93-
if (tp1.refinedInfo.existsPart(toAvoid) && variance > 0) {
88+
if (toAvoid(tp1.refinedInfo) && variance > 0) {
9489
typr.println(s"dropping refinement from $tp1")
9590
parent1
9691
}

tests/pos/escapingRefs.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class Outer {
2-
class Inner
2+
class Inner {
3+
class Inner2
4+
}
35
}
46

57
object Test {
@@ -8,5 +10,11 @@ object Test {
810
val o = new Outer
911
new o.Inner
1012
}
13+
14+
val b: Outer#Inner#Inner2 = {
15+
val o = new Outer
16+
val i = new o.Inner
17+
new i.Inner2
18+
}
1119
}
1220
}

0 commit comments

Comments
 (0)