Type inference at top level
2012-07-26 10:58:47 GMT
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
)
RSS Feed