Skip to content

Commit fbfdf1b

Browse files
committed
Don't force NamedType denotations in containsRefinedThis
containsRefinedThis inspects symbols and infos of named types in order to avoid needless traversals. As i974 shows, this can lead to infinite recursions. The fix is not to force a NamedType denotation, assume the worst and traverse the prefix if a NamedType is not yet populated with a denotation. Fixes scala#974 and makes MutableSortedSetFactory in stdlib compile.
1 parent 84f0280 commit fbfdf1b

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,13 @@ class TypeApplications(val self: Type) extends AnyVal {
698698
case RefinedThis(tp) =>
699699
tp eq target
700700
case tp: NamedType =>
701-
if (tp.symbol.isClass) !tp.symbol.isStatic && recur(tp.prefix)
702-
else tp.info match {
703-
case TypeAlias(alias) => recur(alias)
704-
case _ => recur(tp.prefix)
705-
}
701+
if (tp.denotationIsCurrent)
702+
if (tp.symbol.isClass) !tp.symbol.isStatic && recur(tp.prefix)
703+
else tp.info match {
704+
case TypeAlias(alias) => recur(alias)
705+
case _ => recur(tp.prefix)
706+
}
707+
else recur(tp.prefix)
706708
case tp: RefinedType =>
707709
recur(tp.refinedInfo) || recur(tp.parent)
708710
case tp: TypeBounds =>

test/dotc/scala-collections.whitelist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
./scala-scala/src/library/scala/collection/generic/ParFactory.scala
267267

268268
# https://github.com/lampepfl/dotty/issues/974 -> @smarter
269-
#./scala-scala/src/library/scala/collection/generic/MutableSortedSetFactory.scala
269+
./scala-scala/src/library/scala/collection/generic/MutableSortedSetFactory.scala
270270

271271
# cyclic reference, maybe related to #974 -> @smarter
272272
#./scala-scala/src/library/scala/collection/generic/ParSetFactory.scala

tests/pos/i974.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Foo[A]
2+
class Bar[CC[X] <: Foo[CC[X]]]

0 commit comments

Comments
 (0)