Skip to content

Commit 4fe718b

Browse files
committed
return constrainResult after AmbiguousImplicits
1 parent 9be384b commit 4fe718b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,16 +4250,25 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
42504250
else formals1
42514251
implicitArgs(formals2, argIndex + 1, pt)
42524252

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+
}
42594265
}
4266+
val arg = inferImplicitArg(formal, tree.span.endPos)
42604267
arg.tpe match
42614268
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)
42634272
case failed: SearchFailureType =>
42644273
lazy val defaultArg = findDefaultArgument(argIndex)
42654274
.showing(i"default argument: for $formal, $tree, $argIndex = $result", typr)

0 commit comments

Comments
 (0)