Skip to content

Commit 2dc3b19

Browse files
committed
SI-9231 Don't attempt implicit search for erroneous parameter
If the instantiated type of an implicit parameter is erroneous, we should not attempt the implicit search. This avoids the following useless error message in the enclosed test: error: ambiguous implicit values: ... match expected type M[<error>]
1 parent fa33395 commit 2dc3b19

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
151151
for(ar <- argResultsBuff)
152152
paramTp = paramTp.subst(ar.subst.from, ar.subst.to)
153153

154-
val res = if (paramFailed || (paramTp.isError && {paramFailed = true; true})) SearchFailure else inferImplicit(fun, paramTp, context.reportErrors, isView = false, context)
154+
val res = if (paramFailed || (paramTp.isErroneous && {paramFailed = true; true})) SearchFailure else inferImplicit(fun, paramTp, context.reportErrors, isView = false, context)
155155
argResultsBuff += res
156156

157157
if (res.isSuccess) {

test/files/neg/t9231.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
t9231.scala:8: error: not found: type DoesNotExist
2+
foo[DoesNotExist]
3+
^
4+
one error found

test/files/neg/t9231.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class M[A]
2+
class C {
3+
implicit def M1: M[Int] = null
4+
implicit def M2: M[String] = null
5+
6+
def foo[A](implicit M: M[A]) = null
7+
8+
foo[DoesNotExist]
9+
}

0 commit comments

Comments
 (0)