[scala] Cryptic error for a type definition within block

View: New views
3 Messages — Rating Filter:   Alert me  

[scala] Cryptic error for a type definition within block

by nikov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: [scala] Cryptic error for a type definition within block

by James Iry-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

related to http://lampsvn.epfl.ch/trac/scala/ticket/1201

On Thu, Jun 18, 2009 at 6:32 AM, Vladimir Reshetnikov <v.reshetnikov@...> wrote:
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


Re: [scala] Cryptic error for a type definition within block

by nikov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, James. This is exactly the same.

Vladimir

On 6/18/09, James Iry <jamesiry@...> wrote:

> related to http://lampsvn.epfl.ch/trac/scala/ticket/1201
>
> On Thu, Jun 18, 2009 at 6:32 AM, Vladimir Reshetnikov <
> v.reshetnikov@...> wrote:
>
>> 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
>>
>