From 431e19f9f1a5b62e361579bac6fd321c6c3018d2 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sat, 28 Dec 2013 02:25:29 +0300 Subject: SI-6355 SI-7059 it is possible to overload applyDynamic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As our discussion at https://issues.scala-lang.org/browse/SI-6355 shows, it looks like it is possible to overload applyDynamic, even though a straightforward way is closed. This commit codifies the pattern proposed by @paulp and makes sure that it doesn’t break in the future. --- test/files/neg/t6355.check | 7 ------- test/files/neg/t6355.scala | 19 ------------------- test/files/neg/t6355a.check | 7 +++++++ test/files/neg/t6355a.scala | 19 +++++++++++++++++++ test/files/neg/t6355b.check | 11 +++++++++++ test/files/neg/t6355b.scala | 17 +++++++++++++++++ 6 files changed, 54 insertions(+), 26 deletions(-) delete mode 100644 test/files/neg/t6355.check delete mode 100644 test/files/neg/t6355.scala create mode 100644 test/files/neg/t6355a.check create mode 100644 test/files/neg/t6355a.scala create mode 100644 test/files/neg/t6355b.check create mode 100644 test/files/neg/t6355b.scala (limited to 'test/files/neg') diff --git a/test/files/neg/t6355.check b/test/files/neg/t6355.check deleted file mode 100644 index 607829d99a..0000000000 --- a/test/files/neg/t6355.check +++ /dev/null @@ -1,7 +0,0 @@ -t6355.scala:12: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) - def applyDynamic(name: String)(x: Int): Int = 2 - ^ -t6355.scala:18: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) - def applyDynamic[T1, T2](name: String)(x: String, y: T1, z: T2): Int = 3 - ^ -two errors found diff --git a/test/files/neg/t6355.scala b/test/files/neg/t6355.scala deleted file mode 100644 index 0500ed04c6..0000000000 --- a/test/files/neg/t6355.scala +++ /dev/null @@ -1,19 +0,0 @@ -package foo - -import scala.language.dynamics - -class DoesntExtendDynamic { - def applyDynamic(name: String)(s: String): Int = 1 - def applyDynamic(name: String)(x: Int): Int = 2 -} - -class A extends Dynamic { - def applyDynamic(name: String)(s: String): Int = 1 - def applyDynamic(name: String)(x: Int): Int = 2 -} - -class B extends Dynamic { - def applyDynamic[T1](name: String)(x: T1): Int = 1 - def applyDynamic[T1, T2](name: String)(x: T1, y: T2): Int = 2 - def applyDynamic[T1, T2](name: String)(x: String, y: T1, z: T2): Int = 3 -} diff --git a/test/files/neg/t6355a.check b/test/files/neg/t6355a.check new file mode 100644 index 0000000000..5768d31f0b --- /dev/null +++ b/test/files/neg/t6355a.check @@ -0,0 +1,7 @@ +t6355a.scala:12: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) + def applyDynamic(name: String)(x: Int): Int = 2 + ^ +t6355a.scala:18: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) + def applyDynamic[T1, T2](name: String)(x: String, y: T1, z: T2): Int = 3 + ^ +two errors found diff --git a/test/files/neg/t6355a.scala b/test/files/neg/t6355a.scala new file mode 100644 index 0000000000..0500ed04c6 --- /dev/null +++ b/test/files/neg/t6355a.scala @@ -0,0 +1,19 @@ +package foo + +import scala.language.dynamics + +class DoesntExtendDynamic { + def applyDynamic(name: String)(s: String): Int = 1 + def applyDynamic(name: String)(x: Int): Int = 2 +} + +class A extends Dynamic { + def applyDynamic(name: String)(s: String): Int = 1 + def applyDynamic(name: String)(x: Int): Int = 2 +} + +class B extends Dynamic { + def applyDynamic[T1](name: String)(x: T1): Int = 1 + def applyDynamic[T1, T2](name: String)(x: T1, y: T2): Int = 2 + def applyDynamic[T1, T2](name: String)(x: String, y: T1, z: T2): Int = 3 +} diff --git a/test/files/neg/t6355b.check b/test/files/neg/t6355b.check new file mode 100644 index 0000000000..f827f07e53 --- /dev/null +++ b/test/files/neg/t6355b.check @@ -0,0 +1,11 @@ +t6355b.scala:14: error: value applyDynamic is not a member of A +error after rewriting to x.("bippy") +possible cause: maybe a wrong Dynamic method signature? + println(x.bippy(42)) + ^ +t6355b.scala:15: error: value applyDynamic is not a member of A +error after rewriting to x.("bippy") +possible cause: maybe a wrong Dynamic method signature? + println(x.bippy("42")) + ^ +two errors found diff --git a/test/files/neg/t6355b.scala b/test/files/neg/t6355b.scala new file mode 100644 index 0000000000..5f3c97cb0c --- /dev/null +++ b/test/files/neg/t6355b.scala @@ -0,0 +1,17 @@ +import scala.language.dynamics + +class A extends Dynamic { + def selectDynamic(method: String): B = new B(method) +} +class B(method: String) { + def apply(x: Int) = s"$method(x: Int) called with x = $x" + def apply(x: String) = s"""$method(x: String) called with x = "$x"""" +} + +object Test { + def main(args: Array[String]): Unit = { + val x = new A + println(x.bippy(42)) + println(x.bippy("42")) + } +} -- cgit v1.2.3