@@ -2567,17 +2567,19 @@ class Typer extends Namer
2567
2567
2568
2568
def adaptNoArgs (wtp : Type ): Tree = {
2569
2569
val ptNorm = underlyingApplied(pt)
2570
- lazy val functionExpected = defn.isFunctionType(ptNorm)
2571
- lazy val resultMatch = constrainResult(tree.symbol, wtp, followAlias(pt))
2570
+ def functionExpected = defn.isFunctionType(ptNorm)
2571
+ def resultMatch = constrainResult(tree.symbol, wtp, followAlias(pt))
2572
2572
def needsEta = pt match {
2573
2573
case _ : SingletonType => false
2574
2574
case IgnoredProto (_ : FunOrPolyProto ) => false
2575
2575
case _ => true
2576
2576
}
2577
+ var resMatch : Boolean = false
2577
2578
wtp match {
2578
2579
case wtp : ExprType =>
2579
2580
readaptSimplified(tree.withType(wtp.resultType))
2580
- case wtp : MethodType if wtp.isImplicitMethod && (resultMatch || ! functionExpected) =>
2581
+ case wtp : MethodType if wtp.isImplicitMethod &&
2582
+ ({ resMatch = resultMatch; resMatch } || ! functionExpected) =>
2581
2583
if (resultMatch || ctx.mode.is(Mode .ImplicitsEnabled )) adaptNoArgsImplicitMethod(wtp)
2582
2584
else {
2583
2585
// Don't proceed with implicit search if result type cannot match - the search
@@ -2586,8 +2588,9 @@ class Typer extends Namer
2586
2588
err.typeMismatch(tree, pt)
2587
2589
}
2588
2590
case wtp : MethodType if needsEta =>
2591
+ val funExpected = functionExpected
2589
2592
val arity =
2590
- if (functionExpected )
2593
+ if (funExpected )
2591
2594
if (! isFullyDefined(pt, ForceDegree .none) && isFullyDefined(wtp, ForceDegree .none))
2592
2595
// if method type is fully defined, but expected type is not,
2593
2596
// prioritize method parameter types as parameter types of the eta-expanded closure
@@ -2598,7 +2601,7 @@ class Typer extends Namer
2598
2601
if (nparams > 0 || pt.eq(AnyFunctionProto )) nparams
2599
2602
else - 1 // no eta expansion in this case
2600
2603
}
2601
- adaptNoArgsUnappliedMethod(wtp, functionExpected , arity)
2604
+ adaptNoArgsUnappliedMethod(wtp, funExpected , arity)
2602
2605
case _ =>
2603
2606
adaptNoArgsOther(wtp)
2604
2607
}
0 commit comments