- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
compilation error: value is not member...
Thu, 2009-03-05, 08:40
Its been a while since I used scala... why is the compiler complaining? bug?
class Wally(side:String)
class Fred(w:Wally) {
val w1 = new Wally("A")
def empty = w.side.length
}
~
; fsc fred.scala
/tmp/fred.scala:6: error: value side is not a member of Wally
def empty = w.side.length
^
one error found
; fsc -version
Fast Scala Compiler version 2.7.3.final -- Copyright 2002-2009, LAMP/EPFL
;
thanks,
mark
Thu, 2009-03-05, 09:17
#2
RE: Re: compilation error: value is not member...
> ok, it works, if I remove side from the constructor. What did I miss?
In class Wally(side:String) you defined a constructor parameter, but no
accessible field.
Use class Wally(val side:String) do get a readable field (getter
created),
like you got with your 'solution', or var instead of val to get getter
and
setter created.
KR
Det
>
> ; cat fred.scala
>
> class Wally() {
> val side = "west"
> }
>
> class Fred(w:Wally) {
> def empty = w.side.length
> }
> ; fsc fred.scala
>
>
>
>
>
> On Thu, Mar 5, 2009 at 18:40, Mark Ng wrote:
>
>
>
> Its been a while since I used scala... why is the
> compiler complaining? bug?
>
>
> class Wally(side:String)
>
> class Fred(w:Wally) {
> val w1 = new Wally("A")
> def empty = w.side.length
> }
> ~
>
> ; fsc fred.scala
> /tmp/fred.scala:6: error: value side is not a member of Wally
> def empty = w.side.length
> ^
> one error found
> ; fsc -version
> Fast Scala Compiler version 2.7.3.final -- Copyright
> 2002-2009, LAMP/EPFL
> ;
>
>
> thanks,
> mark
>
>
>
>
>
Thu, 2009-03-05, 09:27
#3
Re: Re: compilation error: value is not member...
Thanks. That explains it. If I had used case classes would have gone the accessors for free....
mark
On Thu, Mar 5, 2009 at 18:55, Detering Dirk <Dirk.Detering@bitmarck.de> wrote:
> ok, it works, if I remove side from the constructor. What did I miss?
In class Wally(side:String) you defined a constructor parameter, but no
accessible field.
Use class Wally(val side:String) do get a readable field (getter
created),
like you got with your 'solution', or var instead of val to get getter
and
setter created.
KR
Det
>
> ; cat fred.scala
>
> class Wally() {
> val side = "west"
> }
>
> class Fred(w:Wally) {
> def empty = w.side.length
> }
> ; fsc fred.scala
>
>
>
>
>
> On Thu, Mar 5, 2009 at 18:40, Mark Ng <z3r0.00@gmail.com> wrote:
>
>
>
> Its been a while since I used scala... why is the
> compiler complaining? bug?
>
>
> class Wally(side:String)
>
> class Fred(w:Wally) {
> val w1 = new Wally("A")
> def empty = w.side.length
> }
> ~
>
> ; fsc fred.scala
> /tmp/fred.scala:6: error: value side is not a member of Wally
> def empty = w.side.length
> ^
> one error found
> ; fsc -version
> Fast Scala Compiler version 2.7.3.final -- Copyright
> 2002-2009, LAMP/EPFL
> ;
>
>
> thanks,
> mark
>
>
>
>
>
Thu, 2009-03-05, 09:37
#4
RE: Re: compilation error: value is not member...
> Thanks. That explains it. If I had used case classes would
> have gone the accessors for free....
Right (the getter). Case classes are specified as "all arguments in the
parameter list of a case class implicitly get a val prefix,
so they are maintained as fields" (Programming in Scala p. 294).
KR
Det
ok, it works, if I remove side from the constructor. What did I miss?
; cat fred.scala
class Wally() {
val side = "west"
}
class Fred(w:Wally) {
def empty = w.side.length
}
; fsc fred.scala
On Thu, Mar 5, 2009 at 18:40, Mark Ng <z3r0.00@gmail.com> wrote: