New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Illegal cyclic error in case of mutually recursive, path-dependent types #7642
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7642?orig=1 |
@paulp said: Somewhat reduced. trait P { type A ; val v: A }
trait Q extends P { type A = v.type }
// ./a.scala:2: error: illegal cyclic reference involving type A
// trait Q extends P { type A = v.type }
// ^
// one error found |
@gkossakowski said: Now, when it comes to reproduction I think yours is slightly different (too small). If you change trait JavaPlatform extends Platform {
type PlatformLoaders = loaders2.type
object loaders2 extends SymbolLoaders {
type LoadersPlatform = JavaPlatform.this.type
val platform: JavaPlatform.this.type = ???
}
val loaders: loaders2.type = loaders2
} then the cyclic error disappears. All we did was an introduction of a dummy object |
@paulp said: Mine is too small if you can fix mine and yours still doesn't typecheck. |
@gkossakowski said: class Foo {
class C1 { val x: C2 }
class C2 { val y: C1 }
} with this (which doesn't compile): class Foo {
type T1 = { val x: T2 }
type T2 = { val y: T1 }
} I gave my original code another whirl. Here's a simplified sample (compared to what I originally reported) which compiles: package test2
abstract class Component1 {
val comp2: Component2 {
val comp1: Component1.this.type
}
def foo: String = "Hello, I'm Component1"
}
abstract class Component2 {
val comp1: Component1 {
val comp2: Component2.this.type
}
}
class Main {
object comp1 extends Component1 {
val comp2: Main.this.comp2.type = Main.this.comp2
}
object comp2 extends Component2 {
val comp1: Main.this.comp1.type = Main.this.comp1
}
} It compiles because we are using nominal types: object comp1 and object comp2. The problem is that I cannot override those objects so I cannot do something like: class SubMain extends Main {
override object comp1 extends Component1 {
val comp2: SubMain.this.comp2.type = SubMain.this.comp2
override def foo: String = "Hello, I'm overriden in SubMain"
}
} |
@paulp said:
|
@gkossakowski said: scalac -Yoverride-objects a.scala
error:
while compiling: a.scala
during phase: refchecks
library version: version 2.10.2
compiler version: version 2.10.2
reconstructed args: -Yoverride-objects
last tree to typer: This(object SubMain)
symbol: object SubMain in package test2 (flags: <module>)
symbol definition: class SubMain extends Main
tpe: test2.SubMain.type
symbol owners: object SubMain -> package test2
context owners: object comp1 -> object SubMain -> package test2
[...]
uncaught exception during compilation: java.lang.AssertionError
error: java.lang.AssertionError: assertion failed: List(value comp1, object comp1)
at scala.reflect.internal.Symbols$Symbol.suchThat(Symbols.scala:1669)
at scala.reflect.internal.Types$class.rebind(Types.scala:3529)
at scala.reflect.internal.Types$class.singleType(Types.scala:3548)
at scala.reflect.internal.SymbolTable.singleType(SymbolTable.scala:13)
at scala.reflect.internal.Types$AsSeenFromMap.apply(Types.scala:4554) |
@paulp said: |
@gkossakowski said: |
@paulp said: trait A {
val x: AnyRef
def f: x.type
}
trait B extends A {
override val x: String
def g = f.length
} |
The following code:
doesn't compile with the cyclic error reported:
According to Adriaan, this should compile. We tried to debug it for a while and the cyclic error is thrown at Types.scala:3507:
because it calls to
sym1.info
.I'm not sure if we'll have time to look more deeply into this. However, I can refer to this ticket from a code where I need to insert casts as work-arounds for this problem.
The text was updated successfully, but these errors were encountered: