Skip to content

Commit 76d8913

Browse files
committed
return resultAlreadyConstrained check
1 parent 58993a0 commit 76d8913

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

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

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

4253+
// try to constrain type before implicit search. See #18763
42534254
def tryConstrainType(pt1: Type): Boolean = {
4255+
// subst dummyArg into FunProto so that we don't have to search for nested implicit
4256+
val tm = new TypeMap:
4257+
def apply(t: Type): Type = t match
4258+
case fp@FunProto(args, resType) =>
4259+
fp.derivedFunProto(
4260+
args.map(arg =>
4261+
if (arg.isInstanceOf[untpd.TypedSplice]) arg
4262+
else dummyArg(arg.typeOpt).withSpan(arg.span)
4263+
),
4264+
mapOver(resType)
4265+
)
4266+
case _ =>
4267+
mapOver(t)
42544268
val ownedVars = ctx.typerState.ownedVars
4255-
val qualifying = (ownedVars -- locked).toList
4256-
if (!formal.isGround && (pt1 `ne` pt) && (pt1 ne sharpenedPt) && (ownedVars ne locked) && !ownedVars.isEmpty && qualifying.nonEmpty) {
4269+
def qualifying = (ownedVars -- locked).toList
4270+
val resultAlreadyConstrained = pt1.isInstanceOf[MethodOrPoly]
4271+
if !formal.isGround
4272+
&& (pt1 `ne` pt)
4273+
&& (pt1 ne sharpenedPt)
4274+
&& (ownedVars ne locked)
4275+
&& !ownedVars.isEmpty
4276+
&& qualifying.nonEmpty
4277+
&& !resultAlreadyConstrained then
42574278
val approxRes = wildApprox(pt1.resultType)
4258-
val tm = new TypeMap:
4259-
def apply(t: Type) = t match
4260-
case fp@FunProto(args, resType) =>
4261-
fp.derivedFunProto(
4262-
args.map(arg =>
4263-
if (arg.isInstanceOf[untpd.TypedSplice]) arg
4264-
else dummyArg(arg.typeOpt).withSpan(arg.span)
4265-
),
4266-
mapOver(resType)
4267-
)
4268-
case _ =>
4269-
mapOver(t)
42704279
val stripedApproxRes = tm(approxRes)
4271-
if (!stripedApproxRes.containsWildcardTypes) {
4280+
if !stripedApproxRes.containsWildcardTypes then
42724281
if ctx.typerState.isCommittable then
4273-
NoViewsAllowed.constrainResult(tree.symbol, wtp.resultType, stripedApproxRes)
4274-
else constrainResult(tree.symbol, wtp.resultType, stripedApproxRes)
4275-
} else {
4276-
false
4277-
}
4278-
} else {
4279-
false
4280-
}
4282+
return NoViewsAllowed.constrainResult(tree.symbol, wtp.resultType, stripedApproxRes)
4283+
else return constrainResult(tree.symbol, wtp.resultType, stripedApproxRes)
4284+
false
42814285
}
42824286

42834287
val pt1 = pt.deepenProtoTrans

0 commit comments

Comments
 (0)