Skip to content

Commit 77a83c6

Browse files
committed
move constrain to function
1 parent 1a8afbc commit 77a83c6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

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

4253-
val ownedVars = ctx.typerState.ownedVars
4254-
val pt1 = pt.deepenProtoTrans
4255-
if ((!formal.isGround) && (formal.simplified `ne` formal) && (pt1 `ne` pt) && (pt1 ne sharpenedPt) && (ownedVars ne locked) && !ownedVars.isEmpty) {
4253+
def tryConstrainType(pt1: Type): Boolean = {
4254+
val ownedVars = ctx.typerState.ownedVars
42564255
val qualifying = (ownedVars -- locked).toList
4257-
if (qualifying.nonEmpty) {
4256+
if ((pt1 `ne` pt) && (pt1 ne sharpenedPt) && (ownedVars ne locked) && !ownedVars.isEmpty && qualifying.nonEmpty) {
42584257
val approxRes = wildApprox(pt1.resultType)
42594258
val tm = new TypeMap:
42604259
def apply(t: Type) = t match
42614260
case fp@FunProto(args, resType) =>
42624261
fp.derivedFunProto(
42634262
args.map(arg =>
4264-
if(arg.isInstanceOf[untpd.TypedSplice]) arg
4263+
if (arg.isInstanceOf[untpd.TypedSplice]) arg
42654264
else dummyArg(arg.typeOpt).withSpan(arg.span)
42664265
),
42674266
mapOver(resType)
42684267
)
42694268
case _ =>
42704269
mapOver(t)
42714270
val stripedApproxRes = tm(approxRes)
4272-
val resultAlreadyConstrained = pt1.isInstanceOf[MethodOrPoly]
4273-
if (!resultAlreadyConstrained && !stripedApproxRes.containsWildcardTypes) {
4271+
if (!stripedApproxRes.containsWildcardTypes) {
42744272
if ctx.typerState.isCommittable then
42754273
NoViewsAllowed.constrainResult(tree.symbol, wtp.resultType, stripedApproxRes)
42764274
else constrainResult(tree.symbol, wtp.resultType, stripedApproxRes)
4275+
} else {
4276+
false
42774277
}
4278+
} else {
4279+
false
42784280
}
42794281
}
4282+
4283+
val pt1 = pt.deepenProtoTrans
4284+
tryConstrainType(pt1)
42804285
val arg = inferImplicitArg(formal, tree.span.endPos)
42814286
arg.tpe match
42824287
case failed: AmbiguousImplicits =>

0 commit comments

Comments
 (0)