Open scabug opened 9 years ago
Imported From: https://issues.scala-lang.org/browse/SI-9040?orig=1 Reporter: @dotta Affected Versions: 2.11.4
still crashes 2.13.15
Scala 3.5.1:
[error] illegal cyclic type reference: alias Object{def from(): Option[TagVersion]} of ... (caught cyclic reference) ... refers back to the type itself
[error]
[error] Run with -explain-cyclic for more details.
[error] type TagVersion = {
[error] ^
[error] ./S.scala:6:5
[error] Found: Null
[error] Required: TagVersion
[error] Note that implicit conversions were not tried because the result of an implicit conversion
[error] must be more specific than TagVersion
[error] null : TagVersion
[error] ^^^^
[error] ./S.scala:9:13
[error] value from is not a member of Any
[error] def foo = tagVersion.from()
[error] ^^^^^^^^^^^^^^^
Probably the cyclic check for type aliases in Scala 2 doesn't recurse into type refinements.
Scala 2 doesn't have a checker, but notices locked symbols during completion.
I tried a quick, cleansing tp.foreach(tp => fullyInitializeSymbol(tp.typeSymbol))
for the rhs in typeDefSig
.
Maybe it's enough to try sym.lock()
. (Edit: lockOK
has the same effect but the check requires an investment in subtlety.)
Scala 2 doesn't have a checker, but notices locked symbols during completion.
🤔
def typedRefinement(templ: Template): Unit = {
val stats = templ.body
if (!stats.isEmpty) {
namer.enterSyms(stats)
// need to delay rest of typedRefinement to avoid cyclic reference errors
debuglog(s"deferred typed refinement")
unit.addPostUnitCheck { () =>
Refinements have a get-out-of-jail-free card so the lock doesn't work.
The test from back in the day looks very similar: https://github.com/scala/scala/commit/86397c940a2b4df6166a9bc9ed3e03d008f4dd57#diff-106425dfd9b57da4e4d204dd3b1fdeead5839e8391d8e5ead89a3e6d63abeaa1
That test looks like what I hit when eagerly sym.lockOK
on completion of alias rhs. I considered an external checker like Scala 3 but did not look further.