Skip to content

Commit 4de8096

Browse files
committed
Fix #7067: type avoidance should handle both ThisType and TypeRef
The test example shows that we could arrive at a type like `A { type T = B }`, where `B` is the type to avoid. Previously, we only handle `ThisType(B)`, in this case we have `TypeRef(B)`. The latter leads to loops in type avoidence.
1 parent 65a404f commit 4de8096

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ trait TypeAssigner {
7070
parent
7171
}
7272

73-
def close(tp: Type) = RecType.closeOver(rt => tp.substThis(cls, rt.recThis))
73+
def close(tp: Type) = RecType.closeOver { rt =>
74+
tp.subst(cls :: Nil, rt.recThis :: Nil).substThis(cls, rt.recThis)
75+
}
7476

7577
def isRefinable(sym: Symbol) = !sym.is(Private) && !sym.isConstructor
7678
val refinableDecls = info.decls.filter(isRefinable)

tests/pos/i7067.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
abstract class Foo[T] {
2+
type Species
3+
def foo(s: Species): Nothing = ???
4+
}
5+
6+
class Test {
7+
def species[T] = {
8+
class FooT extends Foo[T] {
9+
type Species = FooT
10+
}
11+
new FooT()
12+
}
13+
}

0 commit comments

Comments
 (0)