From 394b645dd2d44ff68597527c6c690c73653f1bcb Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 9 May 2014 18:55:10 +0200 Subject: Fix of pos/t2429 This was a hard nut to crack. The problem exemplified by t2429 is that in a situation like val x: T = foo(...) where `foo` needs implicit parameters the expected result type `T` is propagated into the typechecking of foo(...) and consequently also into the implicit parameter search. This is often necessary, for instance to instantiate type parameters. But it can lead to overconstrained searches if in fact the right expansion is val x: T = viewToT(foo(...)(implicit params)) where `viewToT` is some implicit conversion. The fix handles that case by re-hecking the application foo(...) with an empty result type, if the implicit parameter search fails. But the re-checking is very subtle as is explained in the comment to `TyperState#tryWithFallback`. --- tests/pending/pos/t2429.scala | 25 ------------------------- tests/pos/t2429.scala | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-) delete mode 100755 tests/pending/pos/t2429.scala create mode 100755 tests/pos/t2429.scala (limited to 'tests') diff --git a/tests/pending/pos/t2429.scala b/tests/pending/pos/t2429.scala deleted file mode 100755 index 4cda3bde1..000000000 --- a/tests/pending/pos/t2429.scala +++ /dev/null @@ -1,25 +0,0 @@ -object Msg { - trait T - - trait TSeq - - object TSeq { - implicit def fromSeq(s: Seq[T]): TSeq = sys.error("stub") - } - - def render: Unit = { - val msgs: TSeq = (List[(Any, Any)]().flatMap { - case (a, b) => { - a match { - case _ => b match { - case _ => sys.error("stub") - } - } - } - } /*: Seq[T] Adding this type annotation avoids the compile error.*/) - } -} -object Oops { - implicit def someImplicit(s: Seq[_]): String = sys.error("stub") - def item: String = Nil map { case e: Any => e } -} diff --git a/tests/pos/t2429.scala b/tests/pos/t2429.scala new file mode 100755 index 000000000..4cda3bde1 --- /dev/null +++ b/tests/pos/t2429.scala @@ -0,0 +1,25 @@ +object Msg { + trait T + + trait TSeq + + object TSeq { + implicit def fromSeq(s: Seq[T]): TSeq = sys.error("stub") + } + + def render: Unit = { + val msgs: TSeq = (List[(Any, Any)]().flatMap { + case (a, b) => { + a match { + case _ => b match { + case _ => sys.error("stub") + } + } + } + } /*: Seq[T] Adding this type annotation avoids the compile error.*/) + } +} +object Oops { + implicit def someImplicit(s: Seq[_]): String = sys.error("stub") + def item: String = Nil map { case e: Any => e } +} -- cgit v1.2.3