[scala] Bounds on abstract types

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

[scala] Bounds on abstract types

by nikov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Consider this code:

////////////////////////////////////////
trait A {
  type T <: this.type with C
}

trait B extends A {
  type T <: this.type with C
}

trait C extends B {
  type T <: this.type with C
}
////////////////////////////////////////

Scala compiler rejects it:

<console>:11: error: overriding type T in trait B with bounds >:
Nothing <: C.this.type with C;
 type T has incompatible type
         type T <: this.type with C
              ^

But the following is accepted:

////////////////////////////////////////
trait A {
  type T <: this.type with C
}

trait B extends A {
  type T <: this.type with C
}

trait C extends B {
}
////////////////////////////////////////

Can anybody explain, why?

Thanks,
Vladimir

[scala] Re: [scala-user] Bounds on abstract types

by Chris Twiner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jun 19, 2009 at 6:15 PM, Vladimir
Reshetnikov<v.reshetnikov@...> wrote:

> Hi,
>
> Consider this code:
>
> ////////////////////////////////////////
> trait A {
>  type T <: this.type with C
> }
>
> trait B extends A {
>  type T <: this.type with C
> }
>
> trait C extends B {
>  type T <: this.type with C
> }
> ////////////////////////////////////////
>
> Scala compiler rejects it:
>
> <console>:11: error: overriding type T in trait B with bounds >:
> Nothing <: C.this.type with C;
>  type T has incompatible type
>         type T <: this.type with C
>              ^
>
> But the following is accepted:
>
> ////////////////////////////////////////
> trait A {
>  type T <: this.type with C
> }
>
> trait B extends A {
>  type T <: this.type with C
> }
>
> trait C extends B {
> }
> ////////////////////////////////////////
>
> Can anybody explain, why?
>
> Thanks,
> Vladimir
>

With 2.8 trunk (at least via the nightly eclipse build) this error
doesn't occur.  Are you using 2.7.x for testing this?

[scala] Re: [scala-user] Bounds on abstract types

by nikov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oh, my bad.
I used scala interpreter, so the first two C's were another C.
Actually, it compiles without errors.

Thanks,
Vladimir

On 6/19/09, Chris Twiner <chris.twiner@...> wrote:

> On Fri, Jun 19, 2009 at 6:15 PM, Vladimir
> Reshetnikov<v.reshetnikov@...> wrote:
>> Hi,
>>
>> Consider this code:
>>
>> ////////////////////////////////////////
>> trait A {
>>  type T <: this.type with C
>> }
>>
>> trait B extends A {
>>  type T <: this.type with C
>> }
>>
>> trait C extends B {
>>  type T <: this.type with C
>> }
>> ////////////////////////////////////////
>>
>> Scala compiler rejects it:
>>
>> <console>:11: error: overriding type T in trait B with bounds >:
>> Nothing <: C.this.type with C;
>>  type T has incompatible type
>>         type T <: this.type with C
>>              ^
>>
>> But the following is accepted:
>>
>> ////////////////////////////////////////
>> trait A {
>>  type T <: this.type with C
>> }
>>
>> trait B extends A {
>>  type T <: this.type with C
>> }
>>
>> trait C extends B {
>> }
>> ////////////////////////////////////////
>>
>> Can anybody explain, why?
>>
>> Thanks,
>> Vladimir
>>
>
> With 2.8 trunk (at least via the nightly eclipse build) this error
> doesn't occur.  Are you using 2.7.x for testing this?
>