- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Regression (source incompatibility) between 2.8.x and 2.9
Thu, 2011-05-19, 11:11
There seem to have been changes made to visibility rules between 2.8 and 2.9
In 2.8:
In 2.9
Chris
In 2.8:
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_18).Type in expressions to have them evaluated.Type :help for more information.
scala> abstract class Top(val id : String)defined class Top
scala> abstract class Middle(id : String) extends Top(id)defined class Middle
scala> trait T { self : Middle => | def foo = println(id) | }defined trait T
In 2.9
Welcome to Scala version 2.9.0.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_18).Type in expressions to have them evaluated.Type :help for more information.
scala> abstract class Top(val id : String)defined class Top
scala> abstract class Middle(id : String) extends Top(id)defined class Middle
scala> trait T { self : Middle => | def foo = println(id) | }<console>:10: error: value id in class Middle cannot be accessed in T with Middle def foo = println(id) ^
Chris
Fri, 2011-05-20, 10:07
#2
Re: Regression (source incompatibility) between 2.8.x and 2.9
Sure, but in the given example, Middle extends Top, whose constructor
parameter id *is* tagged with val, and hence public.
So trait T should be able to access the id defined in Top, shouldn't
it?
Sébastien
On 19 mai, 14:00, Daniel Sobral wrote:
> Constructor members not tagget with "val" or "var" are private. They
> would not be visible from a inheriting class, so should they be
> visible from a self type? Personally, I think that would be a break of
> encapsulation, and so should be avoided.
>
>
>
> On Thu, May 19, 2011 at 07:11, Chris Marshall wrote:
> > There seem to have been changes made to visibility rules between 2.8 and 2.9
> > In 2.8:
>
> > Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM,
> > Java 1.6.0_18).
> > Type in expressions to have them evaluated.
> > Type :help for more information.
> > scala> abstract class Top(val id : String)
> > defined class Top
> > scala> abstract class Middle(id : String) extends Top(id)
> > defined class Middle
> > scala> trait T { self : Middle =>
> > | def foo = println(id)
> > | }
> > defined trait T
>
> > In 2.9
>
> > Welcome to Scala version 2.9.0.final (Java HotSpot(TM) 64-Bit Server VM,
> > Java 1.6.0_18).
> > Type in expressions to have them evaluated.
> > Type :help for more information.
> > scala> abstract class Top(val id : String)
> > defined class Top
> > scala> abstract class Middle(id : String) extends Top(id)
> > defined class Middle
> > scala> trait T { self : Middle =>
> > | def foo = println(id)
> > | }
> > :10: error: value id in class Middle cannot be accessed in T with
> > Middle
> > def foo = println(id)
> > ^
>
> > Chris
>
> --
> Daniel C. Sobral
>
> I travel to the future all the time.
Fri, 2011-05-20, 10:47
#3
Re: Re: Regression (source incompatibility) between 2.8.x and 2
https://issues.scala-lang.org/browse/SI-4606
On Fri, May 20, 2011 at 11:02 AM, Sébastien Doeraene aka sjrd
wrote:
> Sure, but in the given example, Middle extends Top, whose constructor
> parameter id *is* tagged with val, and hence public.
> So trait T should be able to access the id defined in Top, shouldn't
> it?
>
> Sébastien
Fri, 2011-05-20, 13:57
#4
Re: Re: Regression (source incompatibility) between 2.8.x and 2
On Fri, May 20, 2011 at 06:02, Sébastien Doeraene aka sjrd
wrote:
> Sure, but in the given example, Middle extends Top, whose constructor
> parameter id *is* tagged with val, and hence public.
> So trait T should be able to access the id defined in Top, shouldn't
> it?
Oh... yeah, right. Missed that.
>
> Sébastien
>
> On 19 mai, 14:00, Daniel Sobral wrote:
>> Constructor members not tagget with "val" or "var" are private. They
>> would not be visible from a inheriting class, so should they be
>> visible from a self type? Personally, I think that would be a break of
>> encapsulation, and so should be avoided.
>>
>>
>>
>> On Thu, May 19, 2011 at 07:11, Chris Marshall wrote:
>> > There seem to have been changes made to visibility rules between 2.8 and 2.9
>> > In 2.8:
>>
>> > Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM,
>> > Java 1.6.0_18).
>> > Type in expressions to have them evaluated.
>> > Type :help for more information.
>> > scala> abstract class Top(val id : String)
>> > defined class Top
>> > scala> abstract class Middle(id : String) extends Top(id)
>> > defined class Middle
>> > scala> trait T { self : Middle =>
>> > | def foo = println(id)
>> > | }
>> > defined trait T
>>
>> > In 2.9
>>
>> > Welcome to Scala version 2.9.0.final (Java HotSpot(TM) 64-Bit Server VM,
>> > Java 1.6.0_18).
>> > Type in expressions to have them evaluated.
>> > Type :help for more information.
>> > scala> abstract class Top(val id : String)
>> > defined class Top
>> > scala> abstract class Middle(id : String) extends Top(id)
>> > defined class Middle
>> > scala> trait T { self : Middle =>
>> > | def foo = println(id)
>> > | }
>> > :10: error: value id in class Middle cannot be accessed in T with
>> > Middle
>> > def foo = println(id)
>> > ^
>>
>> > Chris
>>
>> --
>> Daniel C. Sobral
>>
>> I travel to the future all the time.
Constructor members not tagget with "val" or "var" are private. They
would not be visible from a inheriting class, so should they be
visible from a self type? Personally, I think that would be a break of
encapsulation, and so should be avoided.
On Thu, May 19, 2011 at 07:11, Chris Marshall wrote:
> There seem to have been changes made to visibility rules between 2.8 and 2.9
> In 2.8:
>
> Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM,
> Java 1.6.0_18).
> Type in expressions to have them evaluated.
> Type :help for more information.
> scala> abstract class Top(val id : String)
> defined class Top
> scala> abstract class Middle(id : String) extends Top(id)
> defined class Middle
> scala> trait T { self : Middle =>
> | def foo = println(id)
> | }
> defined trait T
>
> In 2.9
>
> Welcome to Scala version 2.9.0.final (Java HotSpot(TM) 64-Bit Server VM,
> Java 1.6.0_18).
> Type in expressions to have them evaluated.
> Type :help for more information.
> scala> abstract class Top(val id : String)
> defined class Top
> scala> abstract class Middle(id : String) extends Top(id)
> defined class Middle
> scala> trait T { self : Middle =>
> | def foo = println(id)
> | }
> :10: error: value id in class Middle cannot be accessed in T with
> Middle
> def foo = println(id)
> ^
>
> Chris
>
>