From a1d17e528ecd8df383665b471cee9b39fe2cdd4e Mon Sep 17 00:00:00 2001 From: Miles Sabin Date: Wed, 3 Jul 2019 13:55:38 +0100 Subject: [PATCH] Reject incomplete implicit dictionaries If any RHS of a recursive implicit dictionary (after pruning) is an EmptyTree, then this indicates that implicit search failed and we should report the overall search as a failure. Fixes scala/bug#11591. --- src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 3 ++- test/files/neg/t11591.check | 4 ++++ test/files/neg/t11591.scala | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/files/neg/t11591.check create mode 100644 test/files/neg/t11591.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index a981c4aa58c0..544f18cb3204 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -351,7 +351,8 @@ trait Contexts { self: Analyzer => } val pruned = prune(List(result.tree), implicitDictionary.map(_._2), Nil) - if(pruned.isEmpty) result + if (pruned.isEmpty) result + else if (pruned.exists(_._2 == EmptyTree)) SearchFailure else { val pos = result.tree.pos val (dictClassSym, dictClass0) = { diff --git a/test/files/neg/t11591.check b/test/files/neg/t11591.check new file mode 100644 index 000000000000..2f7e70ba803f --- /dev/null +++ b/test/files/neg/t11591.check @@ -0,0 +1,4 @@ +byname-implicits-bug.scala:8: error: could not find implicit value for parameter e: Test.A + implicitly[A] + ^ +one error found diff --git a/test/files/neg/t11591.scala b/test/files/neg/t11591.scala new file mode 100644 index 000000000000..407304e9822d --- /dev/null +++ b/test/files/neg/t11591.scala @@ -0,0 +1,9 @@ +object Test { + class A + class B + + implicit def mkA(implicit b: => B): A = ??? + implicit def mkB(implicit a: A, i: Int): B = ??? + + implicitly[A] +}