diff options
author | Jan Niehusmann <jan@gondor.com> | 2012-11-13 22:14:34 +0100 |
---|---|---|
committer | Jan Niehusmann <jan@gondor.com> | 2012-11-16 23:54:11 +0100 |
commit | c6569209dab006e74ccecc0ede6ce7815ac8629c (patch) | |
tree | 32105de312055560c5e2b2fd8b0a089459d460d5 /test | |
parent | 850108886765e99e894f7613f49c1bab3650a0c2 (diff) | |
download | scala-c6569209dab006e74ccecc0ede6ce7815ac8629c.tar.gz scala-c6569209dab006e74ccecc0ede6ce7815ac8629c.tar.bz2 scala-c6569209dab006e74ccecc0ede6ce7815ac8629c.zip |
SI-6663: don't ignore type parameter on selectDynamic invocation
Fix mkInvoke to handle selectDynamic calls of the form
new C.foo[T].xyz
or
new C.foo[T].xyz :U
(where C extends Dynamic)
Without this patch, the type parameter was silently ignored, and
possibly inferred to a different.
This patch fixes mkInvoke to handle these cases, where ctxTree has
the form Select(TypeApply(fun, targs), nme) or Typed(...)
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t6663.check | 6 | ||||
-rw-r--r-- | test/files/neg/t6663.scala | 19 | ||||
-rw-r--r-- | test/files/run/t6663.check | 1 | ||||
-rw-r--r-- | test/files/run/t6663.scala | 17 |
4 files changed, 43 insertions, 0 deletions
diff --git a/test/files/neg/t6663.check b/test/files/neg/t6663.check new file mode 100644 index 0000000000..aa4faa4a46 --- /dev/null +++ b/test/files/neg/t6663.check @@ -0,0 +1,6 @@ +t6663.scala:16: error: type mismatch; + found : String + required: Int + var v = new C(42).foo[String].get :Int + ^ +one error found diff --git a/test/files/neg/t6663.scala b/test/files/neg/t6663.scala new file mode 100644 index 0000000000..4a358dfbc5 --- /dev/null +++ b/test/files/neg/t6663.scala @@ -0,0 +1,19 @@ +import language.dynamics + +class C(v: Any) extends Dynamic { + def selectDynamic[T](n: String): Option[T] = Option(v.asInstanceOf[T]) + def applyDynamic[T](n: String)(): Option[T] = Option(v.asInstanceOf[T]) +} + +object Test extends App { + // this should be converted to + // C(42).selectDynamic[String]("foo").get + // causing a compile error. + + // but, before fixing SI-6663, became + // C(42).selectDynamic("foo").get, ignoring + // the [String] type parameter + var v = new C(42).foo[String].get :Int + println(v) +} + diff --git a/test/files/run/t6663.check b/test/files/run/t6663.check new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/test/files/run/t6663.check @@ -0,0 +1 @@ +42 diff --git a/test/files/run/t6663.scala b/test/files/run/t6663.scala new file mode 100644 index 0000000000..6818d286d9 --- /dev/null +++ b/test/files/run/t6663.scala @@ -0,0 +1,17 @@ +import language.dynamics + +class C(v: Any) extends Dynamic { + def selectDynamic[T](n: String): Option[T] = Option(v.asInstanceOf[T]) + def applyDynamic[T](n: String)(): Option[T] = Option(v.asInstanceOf[T]) +} + +object Test extends App { + // this should be converted to + // C(42).selectDynamic[Int]("foo").get + // but, before fixing SI-6663, became + // C(42).selectDynamic[Nothing]("foo").get + // leading to a ClassCastException + var v = new C(42).foo[Int].get + println(v) +} + |