From b1c22386783754f1ec643b0c620d7fdf55833f88 Mon Sep 17 00:00:00 2001 From: Georgi Krastev Date: Sun, 12 Dec 2021 10:21:17 +0100 Subject: [PATCH] Tweak inferMethodInstance to consider if implicits are enabled When implicits are disabled, we can't recover later with a conversion. Esp. when we are already type checking an implicit conversion. This fixes a regression uncovered in Finch. --- src/compiler/scala/tools/nsc/typechecker/Infer.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 9dbede86660f..49b40e16903b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1076,7 +1076,11 @@ trait Infer extends Checkable { */ def inferMethodInstance(fn: Tree, undetParams: List[Symbol], args: List[Tree], pt0: Type): List[Symbol] = fn.tpe match { - case mt @ MethodType(_, _) => + case mt: MethodType => + // If we can't infer the type parameters, we can recover in `tryTypedApply` with an implicit conversion, + // but only when implicit conversions are enabled. In that case we have to infer the type parameters again. + def noInstanceResult = if (context.implicitsEnabled) undetParams else Nil + try { val pt = if (pt0.typeSymbol == UnitClass) WildcardType else pt0 val formals = formalTypes(mt.paramTypes, args.length) @@ -1101,10 +1105,10 @@ trait Infer extends Checkable { enhanceBounds(adjusted.okParams, adjusted.okArgs, xs1) xs1 } - } else undetParams + } else noInstanceResult } catch ifNoInstance { msg => NoMethodInstanceError(fn, args, msg) - undetParams + noInstanceResult } case x => throw new MatchError(x) }