Skip to content

Commit 6bcf0a6

Browse files
oderskysmarter
authored andcommitted
Fix checkNonCyclic.
Need to also look info refined types. Need to handle case where we hit a NoCompleter again. Fixes #974 and makes MutableSortedSetFactory in stdlib compile.
1 parent a0bf2c7 commit 6bcf0a6

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,20 @@ object Checking {
138138
case SuperType(thistp, _) => isInteresting(thistp)
139139
case AndType(tp1, tp2) => isInteresting(tp1) || isInteresting(tp2)
140140
case OrType(tp1, tp2) => isInteresting(tp1) && isInteresting(tp2)
141-
case _: RefinedType => false
142-
// Note: it's important not to visit parents of RefinedTypes,
143-
// since otherwise spurious #Apply projections might be inserted.
141+
case _: RefinedType => true
144142
case _ => false
145143
}
146144
// If prefix is interesting, check info of typeref recursively, marking the referred symbol
147145
// with NoCompleter. This provokes a CyclicReference when the symbol
148146
// is hit again. Without this precaution we could stackoverflow here.
149147
if (isInteresting(pre)) {
150148
val info = tp.info
151-
val symInfo = tp.symbol.info
152-
if (tp.symbol.exists) tp.symbol.info = SymDenotations.NoCompleter
149+
val sym = tp.symbol
150+
if (sym.infoOrCompleter == SymDenotations.NoCompleter) throw CyclicReference(sym)
151+
val symInfo = sym.info
152+
if (sym.exists) sym.info = SymDenotations.NoCompleter
153153
try checkInfo(info)
154-
finally if (tp.symbol.exists) tp.symbol.info = symInfo
154+
finally if (sym.exists) sym.info = symInfo
155155
}
156156
tp
157157
} catch {

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

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class tests extends CompilerTest {
158158
@Test def neg_finalSealed = compileFile(negDir, "final-sealed", xerrors = 2)
159159
@Test def neg_i705 = compileFile(negDir, "i705-inner-value-class", xerrors = 7)
160160
@Test def neg_i866 = compileFile(negDir, "i866", xerrors = 2)
161+
@Test def neg_i974 = compileFile(negDir, "i974", xerrors = 2)
161162
@Test def neg_moduleSubtyping = compileFile(negDir, "moduleSubtyping", xerrors = 4)
162163
@Test def neg_escapingRefs = compileFile(negDir, "escapingRefs", xerrors = 2)
163164
@Test def neg_instantiateAbstract = compileFile(negDir, "instantiateAbstract", xerrors = 8)

tests/neg/i974.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Foo[T <: Bar[T]#Elem] // error: illegal cyclic reference
2+
trait Bar[T] {
3+
type Elem = T
4+
}
5+
trait Foo2[T <: Bar2[T]#Elem] // error: illegal cyclic reference
6+
trait Bar2[T] {
7+
type Elem = T
8+
}

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)