[scala] odd error message

View: New views
4 Messages — Rating Filter:   Alert me  

[scala] odd error message

by daniel mahler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I thought this might be to much for the type system,
but the error message is odd.

scala> trait X {
    |   type T
    |   def v : T
    | }
defined trait X

scala> def f[Y <: X](y: Y) : Y.T = y.v
<console>:5: error: not found: value Y
      def f[Y <: X](y: Y) : Y.T = y.v
                            ^

I expected some complaint about T not being known at compile time,
but  Y is defined and it is a type, not a value,
and it is not being used as value.

cheers
Daniel

Re: [scala] odd error message

by Ricky Clarkson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Y is being used as a value there (there could be an object called Y
with a type inside it called T).  To use it as a type, you want Y#T
rather than Y.T

2009/10/11 Daniel Mahler <dmahler@...>:

> I thought this might be to much for the type system,
> but the error message is odd.
>
> scala> trait X {
>     |   type T
>     |   def v : T
>     | }
> defined trait X
>
> scala> def f[Y <: X](y: Y) : Y.T = y.v
> <console>:5: error: not found: value Y
>       def f[Y <: X](y: Y) : Y.T = y.v
>                             ^
>
> I expected some complaint about T not being known at compile time,
> but  Y is defined and it is a type, not a value,
> and it is not being used as value.
>
> cheers
> Daniel
>



--
Ricky Clarkson
Java Programmer, AD Holdings
+44 1565 770804
Skype: ricky_clarkson
Google Talk: ricky.clarkson@...

Re: [scala] odd error message

by Colin Bullock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alternatively, if you meant the path-dependent type y.T rather than the type Y#T, you can get this with -Xexperimental (this is a recent 2.8 build but I believe this is present in 2.7.x as well, though I don't have it handy to check at the moment).

scala> trait X {                    
     | type T                       
     | def v: T                     
     | }
defined trait X

scala> def f[Y <: X](y: Y): y.T = y.v
f: [Y <: X](x$0:Y)<param 1.0>#T

- Colin

Re: [scala] odd error message

by daniel mahler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ricky & Colin,

Thanks both suggestions were helpful.
That brings me back to a question I asked earlier.
How can you find out what -Xexperimental & -Xfuture enable for any particular release/build?

thanks
Daniel

On Mon, Oct 12, 2009 at 5:01 PM, Colin Bullock <cmbullock@...> wrote:
Alternatively, if you meant the path-dependent type y.T rather than the type Y#T, you can get this with -Xexperimental (this is a recent 2.8 build but I believe this is present in 2.7.x as well, though I don't have it handy to check at the moment).


scala> trait X {                    
     | type T                       
     | def v: T                     
     | }
defined trait X

scala> def f[Y <: X](y: Y): y.T = y.v
f: [Y <: X](x$0:Y)<param 1.0>#T

- Colin