From 62531258003dba513a21847d58395823d6840363 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 14 Jul 2016 15:01:00 +0200 Subject: Changes to overloading Fix #1381: Overloading is now changed so that we first try without implicit searches. Only if that leaves no applicable alternatives we try again with implicit search turned on. This also fixes test case t2660, which got moved from neg to pos. --- tests/neg/t2660.scala | 47 ----------------------------------------------- tests/pos/t2660.scala | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 47 deletions(-) delete mode 100644 tests/neg/t2660.scala create mode 100644 tests/pos/t2660.scala (limited to 'tests') diff --git a/tests/neg/t2660.scala b/tests/neg/t2660.scala deleted file mode 100644 index 17fe26258..000000000 --- a/tests/neg/t2660.scala +++ /dev/null @@ -1,47 +0,0 @@ -// Dotty deviation. The calls here now are classified as ambiguous. - -package hoho - -class G - -class H extends G - -class A[T](x: T) { - - def this(y: G, z: T) = { - this(z) - print(1) - } - - def this(z: H, h: T) = { - this(h) - print(2) - } -} - -object T { - def main(args: Array[String]): Unit = { - implicit def g2h(g: G): H = new H - new A[Int](new H, 23) // error - // in the context here, either secondary constructor is applicable - // to the other, due to the implicit in scope. So the call is ambiguous. - } -} - - -// A version of t2660 which does not use constructors - -object X { - def f[T](x: T) = ??? - def f[T](y: G, z: T) = ??? - def f[T](z: H, h: T) = ??? -} - -object T2 { - def main(args: Array[String]): Unit = { - implicit def g2h(g: G): H = new H - X.f(new H, 23) // error - } -} - - diff --git a/tests/pos/t2660.scala b/tests/pos/t2660.scala new file mode 100644 index 000000000..695db67b9 --- /dev/null +++ b/tests/pos/t2660.scala @@ -0,0 +1,43 @@ +package hoho + +class G + +class H extends G + +class A[T](x: T) { + + def this(y: G, z: T) = { + this(z) + print(1) + } + + def this(z: H, h: T) = { + this(h) + print(2) + } +} + +object T { + def main(args: Array[String]): Unit = { + implicit def g2h(g: G): H = new H + new A[Int](new H, 23) + } +} + + +// A version of t2660 which does not use constructors + +object X { + def f[T](x: T) = ??? + def f[T](y: G, z: T) = ??? + def f[T](z: H, h: T) = ??? +} + +object T2 { + def main(args: Array[String]): Unit = { + implicit def g2h(g: G): H = new H + X.f(new H, 23) + } +} + + -- cgit v1.2.3