From 26aebfac0c6db18483d0db67bcd7f8faf7684f0d Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 23 Jul 2013 13:38:33 -0700 Subject: SI-7690 ghost error message fails compile I won't even try to explain the error reporting code, because it would have no basis in reality. However this change appears to fix the symptom reported. --- src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/compiler/scala/tools/nsc/typechecker/Implicits.scala') diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 100112fec1..c87de8839f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -60,6 +60,8 @@ trait Implicits { * @return A search result */ def inferImplicit(tree: Tree, pt: Type, reportAmbiguous: Boolean, isView: Boolean, context: Context, saveAmbiguousDivergent: Boolean, pos: Position): SearchResult = { + // Note that the isInvalidConversionTarget seems to make a lot more sense right here, before all the + // work is performed, than at the point where it presently exists. val shouldPrint = printTypings && !context.undetparams.isEmpty val rawTypeStart = if (Statistics.canEnable) Statistics.startCounter(rawTypeImpl) else null val findMemberStart = if (Statistics.canEnable) Statistics.startCounter(findMemberImpl) else null @@ -1335,12 +1337,18 @@ trait Implicits { } } if (result.isSuccess && isView) { + def maybeInvalidConversionError(msg: String) { + // We have to check context.ambiguousErrors even though we are calling "issueAmbiguousError" + // which ostensibly does exactly that before issuing the error. Why? I have no idea. Test is pos/t7690. + if (context.ambiguousErrors) + context.issueAmbiguousError(AmbiguousImplicitTypeError(tree, msg)) + } if (isInvalidConversionTarget(pt)) { - context.issueAmbiguousError(AmbiguousImplicitTypeError(tree, "the result type of an implicit conversion must be more specific than AnyRef")) + maybeInvalidConversionError("the result type of an implicit conversion must be more specific than AnyRef") result = SearchFailure } else if (isInvalidConversionSource(pt)) { - context.issueAmbiguousError(AmbiguousImplicitTypeError(tree, "an expression of type Null is ineligible for implicit conversion")) + maybeInvalidConversionError("an expression of type Null is ineligible for implicit conversion") result = SearchFailure } } -- cgit v1.2.3