You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type parameter ignored in selectDynamic invocation #6663
scala> new C(42).foo[Int].get
java.lang.ClassCastException: java.lang.Integer cannot be cast to scala.runtime.Nothing$
This happens because in Typers.scala, mkInvoke is called with the following cxTree:
new C.(42).foo[Int].get
Note that the outer element of that tree is a Select(..., "get"), and that's not handled by mkInvoke:
val (outer, explicitTargs) = cxTree1 match {
case TypeApply(fun, targs) => (fun, targs)
case Apply(TypeApply(fun, targs), args) => (Apply(fun, args), targs)
case t => (t, Nil)
}
That can be fixed by adding another case:
val (outer, explicitTargs) = cxTree1 match {
case TypeApply(fun, targs) => (fun, targs)
case Apply(TypeApply(fun, targs), args) => (Apply(fun, args), targs)
case Select(TypeApply(fun, targs), nme) => (Select(fun, nme), targs)
case t => (t, Nil)
}
With that change, the examples work as expected:
scala> new C(42).foo[Int]().get
res0: Int = 42
scala> new C(42).foo[Int].get
res1: Int = 42
Jan Niehusmann (jannic) said:
I'd guess that there are other possible contents of cxTree not yet handled. Is there a better way to fix this than to add all such cases manually to mkInvoke?
Activity
scabug commentedon Nov 13, 2012
Imported From: https://issues.scala-lang.org/browse/SI-6663?orig=1
Reporter: Jan Niehusmann (jannic)
scabug commentedon Nov 13, 2012
@paulp said:
Nice job, you're almost there! Sending a pull request with the fix and a test case makes our lives tremendously easier.
scabug commentedon Nov 14, 2012
Jan Niehusmann (jannic) said:
Maybe a duplicate of #6320
scabug commentedon Nov 14, 2012
Jan Niehusmann (jannic) said:
There are similar cases not covered by the mentioned patch:
Here, the [String] parameter is ignored, again. This time because the cxTree starts with the type annotation: (new C.(42).foo[String].get: Int)
Is there an easy way to find everything which can possibly get attached to cxTree?
scabug commentedon Nov 14, 2012
Jan Niehusmann (jannic) said:
scala/scala#1619
scabug commentedon Nov 14, 2012
Jan Niehusmann (jannic) said:
I'd guess that there are other possible contents of cxTree not yet handled. Is there a better way to fix this than to add all such cases manually to mkInvoke?
scabug commentedon Nov 14, 2012
Jan Niehusmann (jannic) said:
pull request against 2.10.x at scala/scala#1621
scabug commentedon Nov 28, 2012
@paulp said:
That PR was merged, but this is not fixed in general; scala/scala#1681 should fix them all.
scabug commentedon Dec 22, 2012
@paulp said:
edbcc64