aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-08-18 17:24:11 +0200
committerMartin Odersky <odersky@gmail.com>2016-08-18 17:49:06 +0200
commitd5ef867b1f89c79f8620129693e4f1e9bc6f617c (patch)
tree90b573d0452c362d6dbe6be0731f22d211d35200 /tests/pos
parent5a5f9d7ed37ca6449ef61ee5e0f6fbf9731df795 (diff)
downloaddotty-d5ef867b1f89c79f8620129693e4f1e9bc6f617c.tar.gz
dotty-d5ef867b1f89c79f8620129693e4f1e9bc6f617c.tar.bz2
dotty-d5ef867b1f89c79f8620129693e4f1e9bc6f617c.zip
Refinements to auto tupling
There's a nasty interaction with auto-tupling and trying to insert an implicit on the qualifier of a call. If the original call fails, we need to "undo" any auto-tupling decisions in calls where an implicit is inserted on the qualifier. Also: Needed to fix canAutoTuple test so that Scala2 feature is checked instead of dotty's. Also: Drop features in dotty.language that duplicate those in scala.language.
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/t2913.scala78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/pos/t2913.scala b/tests/pos/t2913.scala
new file mode 100644
index 000000000..fa91e6f41
--- /dev/null
+++ b/tests/pos/t2913.scala
@@ -0,0 +1,78 @@
+
+class A {
+ def foo(a: Int) = 0
+}
+
+class RichA {
+ def foo(a: String) = 0
+ def foo(a: String, b: String) = 0
+ def foo() = 0
+}
+
+object TestNoAutoTupling {
+ import language.noAutoTupling // try with on and off
+
+ implicit def AToRichA(a: A): RichA = new RichA
+
+ val a = new A
+ a.foo()
+ a.foo(1)
+
+ a.foo("") // Without implicits, a type error regarding invalid argument types is generated at `""`. This is
+ // the same position as an argument, so the 'second try' typing with an Implicit View is tried,
+ // and AToRichA(a).foo("") is found.
+ //
+ // My reading of the spec "7.3 Views" is that `a.foo` denotes a member of `a`, so the view should
+ // not be triggered.
+ //
+ // But perhaps the implementation was changed to solve See https://lampsvn.epfl.ch/trac/scala/ticket/1756
+
+ a.foo("a", "b") // Without implicits, a type error regarding invalid arity is generated at `foo(<error>"", "")`.
+ // Typers#tryTypedApply:3274 only checks if the error is as the same position as `foo`, `"a"`, or `"b"`.
+ // None of these po
+}
+
+// t0851 is essentially the same:
+object test1 {
+ case class Foo[T,T2](f : (T,T2) => String) extends (((T,T2)) => String){
+ def apply(t : T) = (s:T2) => f(t,s)
+ def apply(p : (T,T2)) = f(p._1,p._2)
+ }
+ implicit def g[T](f : (T,String) => String): test1.Foo[T,String] = Foo(f)
+ def main(args : Array[String]) : Unit = {
+ val f = (x:Int,s:String) => s + x
+ println(f(1))
+ ()
+ }
+}
+object Main {
+ def main(args : Array[String]): Unit = {
+ val fn = (a : Int, str : String) => "a: " + a + ", str: " + str
+ implicit def fx[T](f : (T,String) => String): T => String = (x:T) => f(x,null)
+ println(fn(1))
+ ()
+ }
+}
+
+object TestWithAutoTuling {
+
+ implicit def AToRichA(a: A): RichA = new RichA
+
+ val a = new A
+ a.foo()
+ a.foo(1)
+
+ a.foo("") // Without implicits, a type error regarding invalid argument types is generated at `""`. This is
+ // the same position as an argument, so the 'second try' typing with an Implicit View is tried,
+ // and AToRichA(a).foo("") is found.
+ //
+ // My reading of the spec "7.3 Views" is that `a.foo` denotes a member of `a`, so the view should
+ // not be triggered.
+ //
+ // But perhaps the implementation was changed to solve See https://lampsvn.epfl.ch/trac/scala/ticket/1756
+
+ a.foo("a", "b") // Without implicits, a type error regarding invalid arity is generated at `foo(<error>"", "")`.
+ // Typers#tryTypedApply:3274 only checks if the error is as the same position as `foo`, `"a"`, or `"b"`.
+ // None of these po
+}
+