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

auto-completion in the REPL

3 replies
Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 3 days ago.
Spotted a bug in the REPL...
It looks as though auto-completion against a variable is incorrectly working against the concrete implementation that the variable points to, instead of working with the defined type .
Demo:
---
Welcome to Scala version 2.8.0.r18341-b20090718154540 (Java HotSpot(TM) Client VM, Java 1.6.0_10). Type in expressions to have them evaluated.Type :help for more information.
scala> abstract class Foo {     | def fooMethod = 1      | }defined class Foo
scala> class Bar extends Foo {     | def barMethod = 2      | }defined class Bar
scala> val x : Foo = new Barx: Foo = Bar@1afc0f5
scala> x. [tab]
asInstanceOf   barMethod      fooMethod      getClass       isInstanceOf   toString
scala> x.barMethod<console>:8: error: value barMethod is not a member of Foo        x.barMethod         ^
---
With the [tab] indicating auto-completion.
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: auto-completion in the REPL
I don't know if it is a bug, but Paul is certainly aware of it. IIRC, it wasn't particularly easy to get around that.

On Mon, Jul 20, 2009 at 6:10 PM, Kevin Wright <kev.lee.wright@googlemail.com> wrote:
Spotted a bug in the REPL...
It looks as though auto-completion against a variable is incorrectly working against the concrete implementation that the variable points to, instead of working with the defined type .
Demo:
---
Welcome to Scala version 2.8.0.r18341-b20090718154540 (Java HotSpot(TM) Client VM, Java 1.6.0_10). Type in expressions to have them evaluated. Type :help for more information.
scala> abstract class Foo {      | def fooMethod = 1      | } defined class Foo
scala> class Bar extends Foo {      | def barMethod = 2      | } defined class Bar
scala> val x : Foo = new Bar x: Foo = Bar@1afc0f5
scala> x. [tab]
asInstanceOf   barMethod      fooMethod      getClass       isInstanceOf   toString
scala> x.barMethod <console>:8: error: value barMethod is not a member of Foo        x.barMethod          ^
---
With the [tab] indicating auto-completion.



--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: auto-completion in the REPL

On Mon, Jul 20, 2009 at 10:10:23PM +0100, Kevin Wright wrote:
> It looks as though auto-completion against a variable is incorrectly
> working against the concrete implementation that the variable points
> to, instead of working with the defined type .

This is not so much a bug as it is an unimplemented feature. I am aware
of it, but it is not a big priority compared to most of the bugs on my
radar. It happens because completion uses reflection to find things
out, so you see what's really inside (at the JVM level) not what the
scala type system might think is inside.

Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 3 days ago.
Re: auto-completion in the REPL
I suspected as much :)
It's not a big problem for me at the moment, but I imagine it could be if I were working with larger 3rd party libraries and being offered methods that aren't valid in context

On Mon, Jul 20, 2009 at 10:21 PM, Paul Phillips <paulp@improving.org> wrote:
On Mon, Jul 20, 2009 at 10:10:23PM +0100, Kevin Wright wrote:
> It looks as though auto-completion against a variable is incorrectly
> working against the concrete implementation that the variable points
> to, instead of working with the defined type .

This is not so much a bug as it is an unimplemented feature.  I am aware
of it, but it is not a big priority compared to most of the bugs on my
radar.  It happens because completion uses reflection to find things
out, so you see what's really inside (at the JVM level) not what the
scala type system might think is inside.

--
Paul Phillips      | If this is raisin, make toast with it.
Vivid              |
Empiricist         |
i'll ship a pulp   |----------* http://www.improving.org/paulp/ *----------

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