I've minimized the example given there to:
object Main {
class NonGeneric {}
class Generic[T] {}
class Composite {
def contains(setup : Composite => Unit) : Composite = this
}
def generic[T](parent: Composite): Generic[T] = new Generic[T]
def nonGeneric(parent: Composite): NonGeneric = new NonGeneric
new Composite().contains(
nonGeneric // should have type Composite => NonGeneric
)
new Composite().contains(
generic[Int] // should have type Composite => Generic[Int]
)
}
When compiling (with Scala 2.8.1 final), I get this error:
Composite.scala:17: error: polymorphic expression cannot be
instantiated to expected type;
found : => (Main.Composite) => Main.Generic[Int]
required: (Main.Composite) => Unit
generic[Int] // should have type Composite => Generic[Int]
^
one error found
but no problem with nonGeneric.
1. Should there be a difference, or is this really a bug?
2. Why is the found type not "(Main.Composite) => Main.Generic[Int]"?
Yours, Alexey Romanov
What happens is that we perform eta-expansion on nonGeneric and
generic[Int].
In the first case we adapt the eta-expanded expression to the expected
type i.e. Unit so you get something along the lines of
nonGeneric becomes {(parent0: Composite) =>
Main.this.nonGeneric(parent0); ()}
In the second second case adaption is not done with expected type and
later we fail with the implicit search (because there aren't any).
I will have to check if there is a reason for that.
And no, implicits have nothing to do in this case.
Thanks,
hubert
I think this part [1] of the type checker, which references #2624, is relevent.
-jason
[1] http://bit.ly/gsYPT7
[2] lampsvn.epfl.ch/trac/scala/ticket/2624
Yeap, I was looking at the same thing.
hubert
hubert