Skip to content

Commit 629b341

Browse files
committed
avoidCaptures: handle local types, not just terms
Not that the added test case still infers `Local` for the type of `a` because avoidance doesn't handle type variables correctly and because the nesting level checks are too coarse, this doesn't lead to an error because the check for forward references in TreePickler is currently disabled. All these issues are fixed in later commits of this PR.
1 parent b1722a5 commit 629b341

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4715,10 +4715,10 @@ object Types {
47154715
private def avoidCaptures(tp: Type)(using Context): Type =
47164716
val problemSyms = new TypeAccumulator[Set[Symbol]]:
47174717
def apply(syms: Set[Symbol], t: Type): Set[Symbol] = t match
4718-
case ref @ TermRef(NoPrefix, _)
4718+
case ref: NamedType
47194719
// AVOIDANCE TODO: Are there other problematic kinds of references?
47204720
// Our current tests only give us these, but we might need to generalize this.
4721-
if ref.symbol.maybeOwner.nestingLevel > nestingLevel =>
4721+
if (ref.prefix eq NoPrefix) && ref.symbol.maybeOwner.nestingLevel > nestingLevel =>
47224722
syms + ref.symbol
47234723
case _ =>
47244724
foldOver(syms, t)

tests/pos/i8900a.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Inv[T](val elem: T)
2+
object Test {
3+
def unwrap[Outer](inv: Inv[Outer]): Outer = inv.elem
4+
def wrap[Inner](i: Inner): Inv[Inner] = new Inv(i)
5+
6+
val a = unwrap({
7+
class Local
8+
val local = new Local
9+
wrap(local)
10+
})
11+
}

0 commit comments

Comments
 (0)