From c3bcad807db47ee4ab27ac4a725ba5f402667b4d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 18 Jun 2015 15:15:42 +0200 Subject: Do not check for ambiguous implicits in viewExists Previously `viewExists(X, Y)` failed if there were ambiguous implicit conversions from X to Y. This is too fragile, as demonstrated by test case run/array-addition.scala. Here, the `genericArrayOps` implicit was not inserted because its result type `Array[?T]` was deemed to be incompatible with `? { +: : ? }`. It was incompatible because there were multiple implicits that added :+ to arrays of various element types. But once `genericArrayOps` gets applied, the type parameter `?T` of the array result is fixed, and the ambuity goes away. The scenario shows that we should not test for ambiguous implicits in viewExists. Such a test is fragile because it depends on the progress of type inference when the test is made. It's preferable to just test for any implicit conversion to exist and to check for ambiguities later, when the implicit conversion is actually applied. This has also the potential of speeding up implicit search in situations where `viewExists` is called often (e.g. when coupled with overloading resolution). --- tests/pending/run/array-addition.check | 4 ---- tests/pending/run/array-addition.scala | 11 ----------- tests/run/array-addition.check | 4 ++++ tests/run/array-addition.scala | 11 +++++++++++ 4 files changed, 15 insertions(+), 15 deletions(-) delete mode 100644 tests/pending/run/array-addition.check delete mode 100644 tests/pending/run/array-addition.scala create mode 100644 tests/run/array-addition.check create mode 100644 tests/run/array-addition.scala (limited to 'tests') diff --git a/tests/pending/run/array-addition.check b/tests/pending/run/array-addition.check deleted file mode 100644 index 7bfbd9c71..000000000 --- a/tests/pending/run/array-addition.check +++ /dev/null @@ -1,4 +0,0 @@ -Array(1, 2, 3, 4) -Array(1, 2, 3, 4) -Array(1) -Array(1) diff --git a/tests/pending/run/array-addition.scala b/tests/pending/run/array-addition.scala deleted file mode 100644 index 8def48e85..000000000 --- a/tests/pending/run/array-addition.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Test { - def prettyPrintArray(x: Array[_]) = println("Array(" + x.mkString(", ") + ")") - - def main(args: Array[String]): Unit = { - prettyPrintArray(Array(1,2,3) :+ 4) - prettyPrintArray(1 +: Array(2,3,4)) - prettyPrintArray(Array() :+ 1) - prettyPrintArray(1 +: Array()) - } -} - diff --git a/tests/run/array-addition.check b/tests/run/array-addition.check new file mode 100644 index 000000000..7bfbd9c71 --- /dev/null +++ b/tests/run/array-addition.check @@ -0,0 +1,4 @@ +Array(1, 2, 3, 4) +Array(1, 2, 3, 4) +Array(1) +Array(1) diff --git a/tests/run/array-addition.scala b/tests/run/array-addition.scala new file mode 100644 index 000000000..8def48e85 --- /dev/null +++ b/tests/run/array-addition.scala @@ -0,0 +1,11 @@ +object Test { + def prettyPrintArray(x: Array[_]) = println("Array(" + x.mkString(", ") + ")") + + def main(args: Array[String]): Unit = { + prettyPrintArray(Array(1,2,3) :+ 4) + prettyPrintArray(1 +: Array(2,3,4)) + prettyPrintArray(Array() :+ 1) + prettyPrintArray(1 +: Array()) + } +} + -- cgit v1.2.3