diff options
Diffstat (limited to 'tests/neg')
-rw-r--r-- | tests/neg/applydynamic_sip.check | 52 | ||||
-rw-r--r-- | tests/neg/applydynamic_sip.flags | 1 | ||||
-rw-r--r-- | tests/neg/applydynamic_sip.scala | 36 | ||||
-rw-r--r-- | tests/neg/t6355b.check | 11 | ||||
-rw-r--r-- | tests/neg/t6355b.scala | 17 | ||||
-rw-r--r-- | tests/neg/t6663.check | 6 | ||||
-rw-r--r-- | tests/neg/t6663.scala | 19 | ||||
-rw-r--r-- | tests/neg/t6920.check | 6 | ||||
-rw-r--r-- | tests/neg/t6920.scala | 10 | ||||
-rw-r--r-- | tests/neg/t8006.check | 6 | ||||
-rw-r--r-- | tests/neg/t8006.scala | 8 |
11 files changed, 172 insertions, 0 deletions
diff --git a/tests/neg/applydynamic_sip.check b/tests/neg/applydynamic_sip.check new file mode 100644 index 000000000..1bd8304bf --- /dev/null +++ b/tests/neg/applydynamic_sip.check @@ -0,0 +1,52 @@ +tests/neg/applydynamic_sip.scala:8: error: value applyDynamic is not a member of Dynamic(Test.qual) +possible cause: maybe a wrong Dynamic method signature? + qual.sel(a, a2: _*) // error + ^ +tests/neg/applydynamic_sip.scala:9: error: applyDynamicNamed does not support passing a vararg parameter + qual.sel(arg = a, a2: _*) // error + ^ +tests/neg/applydynamic_sip.scala:10: error: applyDynamicNamed does not support passing a vararg parameter + qual.sel(arg, arg2 = "a2", a2: _*) // error + ^ +tests/neg/applydynamic_sip.scala:20: error: type mismatch: + found : String("sel") + required: Int + bad1.sel // error + ^ +tests/neg/applydynamic_sip.scala:21: error: type mismatch: + found : String("sel") + required: Int + bad1.sel(1) // error // error + ^ +tests/neg/applydynamic_sip.scala:21: error: method applyDynamic in class Bad1 does not take more parameters + bad1.sel(1) // error // error + ^ +tests/neg/applydynamic_sip.scala:22: error: type mismatch: + found : String("sel") + required: Int + bad1.sel(a = 1) // error // error + ^ +tests/neg/applydynamic_sip.scala:22: error: method applyDynamicNamed in class Bad1 does not take more parameters + bad1.sel(a = 1) // error // error + ^ +tests/neg/applydynamic_sip.scala:23: error: type mismatch: + found : String("sel") + required: Int + bad1.sel = 1 // error // error + ^ +tests/neg/applydynamic_sip.scala:23: error: method updateDynamic in class Bad1 does not take more parameters + bad1.sel = 1 // error // error + ^ +tests/neg/applydynamic_sip.scala:32: error: method selectDynamic in class Bad2 does not take parameters + bad2.sel // error + ^ +tests/neg/applydynamic_sip.scala:33: error: method applyDynamic in class Bad2 does not take parameters + bad2.sel(1) // error + ^ +tests/neg/applydynamic_sip.scala:34: error: method applyDynamicNamed in class Bad2 does not take parameters + bad2.sel(a = 1) // error + ^ +tests/neg/applydynamic_sip.scala:35: error: method updateDynamic in class Bad2 does not take parameters + bad2.sel = 1 // error + ^ +14 errors found diff --git a/tests/neg/applydynamic_sip.flags b/tests/neg/applydynamic_sip.flags new file mode 100644 index 000000000..1141f9750 --- /dev/null +++ b/tests/neg/applydynamic_sip.flags @@ -0,0 +1 @@ +-language:dynamics diff --git a/tests/neg/applydynamic_sip.scala b/tests/neg/applydynamic_sip.scala new file mode 100644 index 000000000..7b131e7ff --- /dev/null +++ b/tests/neg/applydynamic_sip.scala @@ -0,0 +1,36 @@ +import scala.language.dynamics +object Test extends App { + val qual: Dynamic = ??? + val expr = "expr" + val a = "a" + val a2 = "a2" + + qual.sel(a, a2: _*) // error + qual.sel(arg = a, a2: _*) // error + qual.sel(arg, arg2 = "a2", a2: _*) // error + + class Bad1 extends Dynamic { + def selectDynamic(n: Int) = n + def applyDynamic(n: Int) = n + def applyDynamicNamed(n: Int) = n + def updateDynamic(n: Int) = n + + } + val bad1 = new Bad1 + bad1.sel // error + bad1.sel(1) // error // error + bad1.sel(a = 1) // error // error + bad1.sel = 1 // error // error + + class Bad2 extends Dynamic { + def selectDynamic = 1 + def applyDynamic = 1 + def applyDynamicNamed = 1 + def updateDynamic = 1 + } + val bad2 = new Bad2 + bad2.sel // error + bad2.sel(1) // error + bad2.sel(a = 1) // error + bad2.sel = 1 // error +} diff --git a/tests/neg/t6355b.check b/tests/neg/t6355b.check new file mode 100644 index 000000000..fb73b9c42 --- /dev/null +++ b/tests/neg/t6355b.check @@ -0,0 +1,11 @@ +t6355b.scala:14: error: value applyDynamic is not a member of A +error after rewriting to x.<applyDynamic: error>("bippy") +possible cause: maybe a wrong Dynamic method signature? + println(x.bippy(42)) // error + ^ +t6355b.scala:15: error: value applyDynamic is not a member of A +error after rewriting to x.<applyDynamic: error>("bippy") +possible cause: maybe a wrong Dynamic method signature? + println(x.bippy("42")) // error + ^ +two errors found diff --git a/tests/neg/t6355b.scala b/tests/neg/t6355b.scala new file mode 100644 index 000000000..bba3c4fdc --- /dev/null +++ b/tests/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)) // error + println(x.bippy("42")) // error + } +} diff --git a/tests/neg/t6663.check b/tests/neg/t6663.check new file mode 100644 index 000000000..aa4faa4a4 --- /dev/null +++ b/tests/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/tests/neg/t6663.scala b/tests/neg/t6663.scala new file mode 100644 index 000000000..aa4ab08ed --- /dev/null +++ b/tests/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 // error + println(v) +} + diff --git a/tests/neg/t6920.check b/tests/neg/t6920.check new file mode 100644 index 000000000..8bfd16a5f --- /dev/null +++ b/tests/neg/t6920.check @@ -0,0 +1,6 @@ +t6920.scala:9: error: too many arguments for method applyDynamicNamed: (values: Seq[(String, Any)])String +error after rewriting to CompilerError.this.test.applyDynamicNamed("crushTheCompiler")(scala.Tuple2("a", 1), scala.Tuple2("b", 2)) +possible cause: maybe a wrong Dynamic method signature? + test.crushTheCompiler(a = 1, b = 2) // error + ^ +one error found diff --git a/tests/neg/t6920.scala b/tests/neg/t6920.scala new file mode 100644 index 000000000..9601ed8d2 --- /dev/null +++ b/tests/neg/t6920.scala @@ -0,0 +1,10 @@ +import scala.language.dynamics + +class DynTest extends Dynamic { + def applyDynamicNamed(name: String)(values: Seq[(String, Any)]) = "test" +} + +class CompilerError { + val test = new DynTest + test.crushTheCompiler(a = 1, b = 2) // error +} diff --git a/tests/neg/t8006.check b/tests/neg/t8006.check new file mode 100644 index 000000000..98207ba30 --- /dev/null +++ b/tests/neg/t8006.check @@ -0,0 +1,6 @@ +t8006.scala:3: error: too many arguments for method applyDynamicNamed: (value: (String, Any))String +error after rewriting to X.this.d.applyDynamicNamed("meth")(scala.Tuple2("value1", 10), scala.Tuple2("value2", 100)) +possible cause: maybe a wrong Dynamic method signature? + d.meth(value1 = 10, value2 = 100) // error: two arguments here, but only one is allowed + ^ +one error found diff --git a/tests/neg/t8006.scala b/tests/neg/t8006.scala new file mode 100644 index 000000000..34946a659 --- /dev/null +++ b/tests/neg/t8006.scala @@ -0,0 +1,8 @@ +object X { + val d = new D + d.meth(value1 = 10, value2 = 100) // error: two arguments here, but only one is allowed +} +import language.dynamics +class D extends Dynamic { + def applyDynamicNamed(name: String)(value: (String, Any)) = name +} |