Harriet | 26 Jul 2012 12:58
Picon

Type inference at top level

Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet
√iktor Ҡlang | 26 Jul 2012 13:04
Picon

Re: Type inference at top level

You always have to specify type parameters when you extend a parameterized type.


Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang

Chris Marshall | 26 Jul 2012 13:09
Picon
Gravatar

Re: Type inference at top level

But, Viktor, that is not true. As Harriet says, the following compiles just fine


object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang

Chris Marshall | 26 Jul 2012 13:15
Picon
Gravatar

Re: Type inference at top level

And the issue *also* goes away if you remove the implicit


    abstract class A[I](i: I)

  class B

  class C extends A(new B)

is also OK. 

On Thu, Jul 26, 2012 at 12:09 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
But, Viktor, that is not true. As Harriet says, the following compiles just fine

object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang


√iktor Ҡlang | 26 Jul 2012 13:17
Picon

Re: Type inference at top level



On Thu, Jul 26, 2012 at 1:15 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
And the issue *also* goes away if you remove the implicit

    abstract class A[I](i: I)

  class B

  class C extends A(new B)

is also OK. 

I stand corrected. Type parameter inference on extends... wow... why?
 

On Thu, Jul 26, 2012 at 12:09 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
But, Viktor, that is not true. As Harriet says, the following compiles just fine

object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang

Josh Suereth | 26 Jul 2012 13:52
Picon
Gravatar

Re: Type inference at top level

I believe the correct question is "why not?" else we migrate back towards verbosity in types.

On Jul 26, 2012 7:17 AM, "√iktor Ҡlang" <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:15 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
And the issue *also* goes away if you remove the implicit

    abstract class A[I](i: I)

  class B

  class C extends A(new B)

is also OK. 

I stand corrected. Type parameter inference on extends... wow... why?
 

On Thu, Jul 26, 2012 at 12:09 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
But, Viktor, that is not true. As Harriet says, the following compiles just fine

object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang

√iktor Ҡlang | 26 Jul 2012 13:54
Picon

Re: Type inference at top level



On Thu, Jul 26, 2012 at 1:52 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:

I believe the correct question is "why not?" else we migrate back towards verbosity in types.

I always put return types on methods. Am I a bad person? :(

 
On Jul 26, 2012 7:17 AM, "√iktor Ҡlang" <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:15 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
And the issue *also* goes away if you remove the implicit

    abstract class A[I](i: I)

  class B

  class C extends A(new B)

is also OK. 

I stand corrected. Type parameter inference on extends... wow... why?
 

On Thu, Jul 26, 2012 at 12:09 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
But, Viktor, that is not true. As Harriet says, the following compiles just fine

object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang




--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang

Josh Suereth | 26 Jul 2012 13:58
Picon
Gravatar

Re: Type inference at top level

No, but they're optional right? 


In Scala, there's good reason to do so, I even recommend it for public methods.   However, I think we should push type inference as far as possible in all aspects, just for those times when it is convenient and non-ambiguous.

- Josh

On Thu, Jul 26, 2012 at 7:54 AM, √iktor Ҡlang <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:52 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:

I believe the correct question is "why not?" else we migrate back towards verbosity in types.

I always put return types on methods. Am I a bad person? :(

 
On Jul 26, 2012 7:17 AM, "√iktor Ҡlang" <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:15 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
And the issue *also* goes away if you remove the implicit

    abstract class A[I](i: I)

  class B

  class C extends A(new B)

is also OK. 

I stand corrected. Type parameter inference on extends... wow... why?
 

On Thu, Jul 26, 2012 at 12:09 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
But, Viktor, that is not true. As Harriet says, the following compiles just fine

object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang




--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang


√iktor Ҡlang | 26 Jul 2012 14:01
Picon

Re: Type inference at top level



On Thu, Jul 26, 2012 at 1:58 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:
No, but they're optional right? 

In Scala, there's good reason to do so, I even recommend it for public methods.   However, I think we should push type inference as far as possible in all aspects, just for those times when it is convenient and non-ambiguous.

Yup. However, I would probably consider it bad practice not to be explicit about type parameters when subclassing.

Cheers,
 

- Josh


On Thu, Jul 26, 2012 at 7:54 AM, √iktor Ҡlang <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:52 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:

I believe the correct question is "why not?" else we migrate back towards verbosity in types.

I always put return types on methods. Am I a bad person? :(

 
On Jul 26, 2012 7:17 AM, "√iktor Ҡlang" <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:15 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
And the issue *also* goes away if you remove the implicit

    abstract class A[I](i: I)

  class B

  class C extends A(new B)

is also OK. 

I stand corrected. Type parameter inference on extends... wow... why?
 

On Thu, Jul 26, 2012 at 12:09 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
But, Viktor, that is not true. As Harriet says, the following compiles just fine

object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang




--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang

Josh Suereth | 26 Jul 2012 14:06
Picon
Gravatar

Re: Type inference at top level

In the example above?  really?


Constructors are kind of like method calls.   extends is kind of like extending a constructor.

def foo[T](t: T): ? = ?
def bar = foo(5)

class A[T](t: T)
class B extends A(5)


eh?

On Thu, Jul 26, 2012 at 8:01 AM, √iktor Ҡlang <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:58 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:
No, but they're optional right? 

In Scala, there's good reason to do so, I even recommend it for public methods.   However, I think we should push type inference as far as possible in all aspects, just for those times when it is convenient and non-ambiguous.

Yup. However, I would probably consider it bad practice not to be explicit about type parameters when subclassing.

Cheers,
 

- Josh


On Thu, Jul 26, 2012 at 7:54 AM, √iktor Ҡlang <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:52 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:

I believe the correct question is "why not?" else we migrate back towards verbosity in types.

I always put return types on methods. Am I a bad person? :(

 
On Jul 26, 2012 7:17 AM, "√iktor Ҡlang" <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:15 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
And the issue *also* goes away if you remove the implicit

    abstract class A[I](i: I)

  class B

  class C extends A(new B)

is also OK. 

I stand corrected. Type parameter inference on extends... wow... why?
 

On Thu, Jul 26, 2012 at 12:09 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
But, Viktor, that is not true. As Harriet says, the following compiles just fine

object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang




--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang


√iktor Ҡlang | 26 Jul 2012 14:10
Picon

Re: Type inference at top level



On Thu, Jul 26, 2012 at 2:06 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:
In the example above?  really?

Constructors are kind of like method calls.   extends is kind of like extending a constructor.

def foo[T](t: T): ? = ?
def bar = foo(5)

class A[T](t: T)
class B extends A(5)


eh?

That argument I can buy!
(I'd still put the return type on "bar" tho :-) )
 

On Thu, Jul 26, 2012 at 8:01 AM, √iktor Ҡlang <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:58 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:
No, but they're optional right? 

In Scala, there's good reason to do so, I even recommend it for public methods.   However, I think we should push type inference as far as possible in all aspects, just for those times when it is convenient and non-ambiguous.

Yup. However, I would probably consider it bad practice not to be explicit about type parameters when subclassing.

Cheers,
 

- Josh


On Thu, Jul 26, 2012 at 7:54 AM, √iktor Ҡlang <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:52 PM, Josh Suereth <joshua.suereth <at> gmail.com> wrote:

I believe the correct question is "why not?" else we migrate back towards verbosity in types.

I always put return types on methods. Am I a bad person? :(

 
On Jul 26, 2012 7:17 AM, "√iktor Ҡlang" <viktor.klang <at> gmail.com> wrote:


On Thu, Jul 26, 2012 at 1:15 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
And the issue *also* goes away if you remove the implicit

    abstract class A[I](i: I)

  class B

  class C extends A(new B)

is also OK. 

I stand corrected. Type parameter inference on extends... wow... why?
 

On Thu, Jul 26, 2012 at 12:09 PM, Chris Marshall <oxbowlakes <at> gmail.com> wrote:
But, Viktor, that is not true. As Harriet says, the following compiles just fine

object wrap {
  class A[T](t: T)

  class B(implicit i: Int)

  class C(implicit i: Int) extends A(new B) 
}

On Thursday, 26 July 2012 12:04:57 UTC+1, √iktor Klang wrote:
You always have to specify type parameters when you extend a parameterized type.

Cheers,


On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
Hi all,

I'm using scalac 2.9.2, and the following code at the top level doesn't compile:

class A[T](t: T)

class B(implicit i: Int)

class C(implicit i: Int) extends A(new B)

The error messages from the compiler don't shed much light on what's wrong:

test.scala:5: error: could not find implicit value for parameter i: Int
class C(implicit i: Int) extends A(new B)
                                   ^
test.scala:5: error: too many arguments for constructor Object: ()java.lang.Object
class C(implicit i: Int) extends A(new B)
       ^
two errors found

Changing the last line to

class C(implicit i: Int) extends A[B](new B)

makes it compile. Wrapping it all in an object also makes it compile.

Is this behaviour (type inference happening inside an object, but not at the top level) intentional? If so, would it be possible for the compiler give a more informative error message?

Regards,
Harriet



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang




--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang





--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: <at> viktorklang

Jason Zaugg | 26 Jul 2012 13:11
Picon
Gravatar

Re: Type inference at top level

On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
> I'm using scalac 2.9.2, and the following code at the top level doesn't
> compile:
>
>> class A[T](t: T)
>>
>> class B(implicit i: Int)
>>
>> class C(implicit i: Int) extends A(new B)
>
>
> The error messages from the compiler don't shed much light on what's wrong:
>
>> test.scala:5: error: could not find implicit value for parameter i: Int
>> class C(implicit i: Int) extends A(new B)
>>                                    ^
>> test.scala:5: error: too many arguments for constructor Object:
>> ()java.lang.Object
>> class C(implicit i: Int) extends A(new B)
>>        ^
>> two errors found
>
>
> Changing the last line to
>
>> class C(implicit i: Int) extends A[B](new B)
>
>
> makes it compile. Wrapping it all in an object also makes it compile.
>
> Is this behaviour (type inference happening inside an object, but not at the
> top level) intentional? If so, would it be possible for the compiler give a
> more informative error message?

https://issues.scala-lang.org/browse/SI-3439

-jason

Johannes Rudolph | 26 Jul 2012 14:34

Re: Type inference at top level

On Thu, Jul 26, 2012 at 1:11 PM, Jason Zaugg <jzaugg <at> gmail.com> wrote:
> On Thu, Jul 26, 2012 at 12:58 PM, Harriet <flying.attack.bunny <at> gmail.com> wrote:
>>> class C(implicit i: Int) extends A(new B)
>>
>> The error messages from the compiler don't shed much light on what's wrong:
>>
>>> test.scala:5: error: could not find implicit value for parameter i: Int
>>> class C(implicit i: Int) extends A(new B)
>>>                                    ^
>
> https://issues.scala-lang.org/browse/SI-3439

So, to sum up: The compiler currently has a bug where it doesn't
manage to have `implicit i` in scope to make it available to the
super-constructor call `A(new B)`. Basically, that's what the first
error message says (without mentioning that it's a bug, of course).

This bug can be worked around by adding an enclosing object definition
or providing the type parameter to the super constructor call. Right?
Very weird, indeed...

--

-- 
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net

Paul Phillips | 26 Jul 2012 15:48

Re: Type inference at top level



On Thu, Jul 26, 2012 at 5:34 AM, Johannes Rudolph <johannes.rudolph <at> googlemail.com> wrote:
The compiler currently has a bug where it doesn't
manage to have `implicit i` in scope to make it available to the
super-constructor call `A(new B)`.

Right, it's a little buried in my comments but you can see what is happening a little ways down the page when it says: "error: `implicit' modifier cannot be used for top-level objects"

That is, to set everything up to infer the type parameter, it tries to place the implicit immediately outside the scope of the supercall, which if the top level does not allow the implicit modifier.


Gmane