Skip to content

Commit 6b7b9d2

Browse files
committed
Treat ThisTypes like TermRefs in NamedPartsAccumulator
widen only if `widenSingletons` is true.
1 parent 207c81c commit 6b7b9d2

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ object TypeOps:
386386
@threadUnsafe lazy val forbidden = symsToAvoid.toSet
387387
def toAvoid(sym: Symbol) = !sym.isStatic && forbidden.contains(sym)
388388
def partsToAvoid =
389-
new NamedPartsAccumulator(tp => toAvoid(tp.symbol), widenTermRefs = true)
389+
new NamedPartsAccumulator(tp => toAvoid(tp.symbol), widenSingletons = true)
390390
def apply(tp: Type): Type = tp match {
391391
case tp: TermRef
392392
if toAvoid(tp.symbol) || partsToAvoid(mutable.Set.empty, tp.info).nonEmpty =>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ object Types {
393393
* types will be ignored.
394394
*/
395395
def namedPartsWith(p: NamedType => Boolean,
396-
widenTermRefs: Boolean = false,
396+
widenSingletons: Boolean = false,
397397
excludeLowerBounds: Boolean = false)
398398
(implicit ctx: Context): collection.Set[NamedType] =
399-
new NamedPartsAccumulator(p, widenTermRefs, excludeLowerBounds).apply(mutable.LinkedHashSet(), this)
399+
new NamedPartsAccumulator(p, widenSingletons, excludeLowerBounds).apply(mutable.LinkedHashSet(), this)
400400

401401
/** Map function `f` over elements of an AndType, rebuilding with function `g` */
402402
def mapReduceAnd[T](f: Type => T)(g: (T, T) => T)(implicit ctx: Context): T = stripTypeVar match {
@@ -5452,7 +5452,7 @@ object Types {
54525452
}
54535453

54545454
class NamedPartsAccumulator(p: NamedType => Boolean,
5455-
widenTermRefs: Boolean = false,
5455+
widenSingletons: Boolean = false,
54565456
excludeLowerBounds: Boolean = false)
54575457
(implicit ctx: Context) extends TypeAccumulator[mutable.Set[NamedType]] {
54585458
override def stopAtStatic: Boolean = false
@@ -5470,9 +5470,9 @@ object Types {
54705470
foldOver(maybeAdd(x, tp), tp)
54715471
case tp: TermRef =>
54725472
val x1 = foldOver(maybeAdd(x, tp), tp)
5473-
if widenTermRefs then apply(x1, tp.underlying) else x1
5473+
if widenSingletons then apply(x1, tp.underlying) else x1
54745474
case tp: ThisType =>
5475-
apply(x, tp.tref)
5475+
if widenSingletons then apply(x, tp.tref) else x
54765476
case NoPrefix =>
54775477
foldOver(x, tp)
54785478
case tp: AppliedType =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ class Typer extends Namer
862862
lazy val locals = localSyms.toSet
863863
block.tpe.namedPartsWith(
864864
tp => locals.contains(tp.symbol) && !tp.isErroneous,
865-
widenTermRefs = true)
865+
widenSingletons = true)
866866
}
867867

868868
/** Ensure that an expression's type can be expressed without references to locally defined

0 commit comments

Comments
 (0)