@@ -4250,16 +4250,25 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4250
4250
else formals1
4251
4251
implicitArgs(formals2, argIndex + 1 , pt)
4252
4252
4253
- val newctx = ctx.fresh.setExploreTyperState()
4254
- val pt1 = pt.deepenProtoTrans(using newctx)
4255
- val arg = if ((formal.simplified `ne` formal) && (pt1 `ne` pt) && (pt1 ne sharpenedPt) && constrainResult(tree.symbol, wtp, pt1)(using newctx)) {
4256
- inferImplicitArg(formal.simplified(using newctx), tree.span.endPos)
4257
- } else {
4258
- inferImplicitArg(formal, tree.span.endPos)
4253
+ val ownedVars = ctx.typerState.ownedVars
4254
+ val pt1 = pt.deepenProtoTrans
4255
+ if ((formal.simplified `ne` formal) && (pt1 `ne` pt) && (pt1 ne sharpenedPt) && (ownedVars ne locked) && ! ownedVars.isEmpty) {
4256
+ val qualifying = (ownedVars -- locked).toList
4257
+ if (qualifying.nonEmpty) {
4258
+ val resultAlreadyConstrained = pt1.isInstanceOf [MethodOrPoly ]
4259
+ if (! resultAlreadyConstrained) {
4260
+ if ctx.typerState.isCommittable then
4261
+ NoViewsAllowed .constrainResult(tree.symbol, wtp, pt1)
4262
+ else constrainResult(tree.symbol, wtp, pt1)
4263
+ }
4264
+ }
4259
4265
}
4266
+ val arg = inferImplicitArg(formal, tree.span.endPos)
4260
4267
arg.tpe match
4261
4268
case failed : AmbiguousImplicits =>
4262
- arg :: implicitArgs(formals1, argIndex + 1 , pt1)
4269
+ if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && constrainResult(tree.symbol, wtp, pt1)
4270
+ then implicitArgs(formals, argIndex, pt)
4271
+ else arg :: implicitArgs(formals1, argIndex + 1 , pt)
4263
4272
case failed : SearchFailureType =>
4264
4273
lazy val defaultArg = findDefaultArgument(argIndex)
4265
4274
.showing(i " default argument: for $formal, $tree, $argIndex = $result" , typr)
0 commit comments