« Return to Thread: [scala] Cryptic error for a type definition within block

[scala] Cryptic error for a type definition within block

by nikov :: Rate this Message:

Reply to Author | View in Thread

Hi,

I try to compile this:

////////////////////////
object A {
  def f = {
    object B
    B
  }
  val x = f
}
////////////////////////

The result is a rather cryptic error:

a.scala:6: error: type mismatch;
 found   : B.type(in object A) where type B.type(in object A) <: B
with Singleton
 required: B.type(in value x) forSome { type B.type(in value x) <: B
with Singleton; type B <: java.lang.Object with ScalaObject }
  val x = f
      ^

Interesting that it appears not in the definition of f, but in the
definition of x (and disappears if the line val x = f is removed).
Can anybody explain this in more detail?

Thanks,
Vladimir

 « Return to Thread: [scala] Cryptic error for a type definition within block