Skip to content

Commit f315852

Browse files
committed
BUG: The use of isDerivedValueClass in ExtensionMethods causes cyclic references
In scala#411 I implemented value classes and started getting errors in the backend. This commit reproduces similar errors in master with a single change: In master Symbol#isDerivedValueClass always return false because value classes are non-functional, after this commit it still always return false but it calls this.derivesFrom(defn.AnyValClass) first, this is enough to trigger the problem. Here's what's happening with dotc_reporter for example, the first error is: dotty.tools.dotc.core.Types$CyclicReference: cyclic reference involving class FlatHashTable - During Erasure, isDerivedValueClass is called on the class FlatHashTable - derivesFrom forces the computation of the base classes of FlatHashTable - HashUtils is a parent of FlatHashTable, its denotation is forced - HashUtils is then transformed by ExplicitOuter which calls isStatic on it - isStatic calls owner.isStaticOwner, this forces the denotation of the owner of HashUtils, which is the module class FlatHashTable$ - FlatHashTable$ is then transformed by ExtensionMethods which calls linkedClass on it to get the companion class FlatHashTable - isDerivedValueClass is called on the class FlatHashTable - *BOOM*
1 parent 1a1f878 commit f315852

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,11 @@ object Symbols {
418418
def filter(p: Symbol => Boolean): Symbol = if (p(this)) this else NoSymbol
419419

420420
/** Is this symbol a user-defined value class? */
421-
final def isDerivedValueClass(implicit ctx: Context): Boolean =
421+
final def isDerivedValueClass(implicit ctx: Context): Boolean = {
422+
this.derivesFrom(defn.AnyValClass) // Simulate ValueClasses.isDerivedValueClass
422423
false // will migrate to ValueClasses.isDerivedValueClass;
423424
// unsupported value class code will continue to use this stub while it exists
425+
}
424426

425427
/** The current name of this symbol */
426428
final def name(implicit ctx: Context): ThisName = denot.name.asInstanceOf[ThisName]

0 commit comments

Comments
 (0)