This page is no longer maintained — Please continue to the home page at www.scala-lang.org

compilation error: value is not member...

4 replies
Mark Ng
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.

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

Mark Ng
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
Re: compilation error: value is not member...

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:

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


Detering Dirk
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
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
>
>
>
>
>

Mark Ng
Joined: 2009-03-05,
User offline. Last seen 42 years 45 weeks ago.
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
>
>
>
>
>

Detering Dirk
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
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

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland