- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: self type is not inherited
Fri, 2009-02-06, 11:49
Could you elaborate on the "don't work on the outside" part?
Sean McDirmid wrote:
>
> Easy, just avoid self types:
>
> trait B {
> def self : A
> protected implicit def coerce(b : this.type) : A = self
> }
>
> They don't work on the outside anyways, so I always role my own. Just
> remember to close the loop (self = this) when you create a concrete
> sub-class.
>
> Sean
>
>
>
>
> On Sun, Oct 12, 2008 at 12:52 AM, Mushtaq Ahmed
> wrote:
>>
>> Given that,
>>
>> trait A
>> trait B {this: A =>}
>>
>> Each time we extend B, we need to explicitly specify the self type as A:
>>
>> trait C extends B {this: A =>}
>> trait D extends B {this: A =>}
>> trait E extends B {this: A =>}
>>
>> Can't this repetition be avoided? Shouldn't self type of C, D and E
>> default
>> to A unless explicitly specified otherwise? Currently, this gives the
>> following error:
>>
>> trait F extends B
>> error: illegal inheritance; self-type F does not conform to B's selftype
>> B
>> with A
>>
>> Regards,
>> Mushtaq
>> --
>> View this message in context:
>> http://www.nabble.com/self-type-is-not-inherited-tp19934242p19934242.html
>> Sent from the Scala mailing list archive at Nabble.com.
>>
>>
>
>