Skip to content

Commit 5ec51bc

Browse files
committed
Approximate result type before constrain
1 parent 9f3c727 commit 5ec51bc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,11 +4255,18 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
42554255
if ((!formal.isGround) && (formal.simplified `ne` formal) && (pt1 `ne` pt) && (pt1 ne sharpenedPt) && (ownedVars ne locked) && !ownedVars.isEmpty) {
42564256
val qualifying = (ownedVars -- locked).toList
42574257
if (qualifying.nonEmpty) {
4258+
val approxRes = wildApprox(pt1.resultType)
4259+
val tm = new TypeMap:
4260+
def apply(t: Type) = t match
4261+
case fp@FunProto(args, resType) =>
4262+
fp.derivedFunProto(args.map(a => dummyArg(a.typeOpt).withSpan(a.span)), mapOver(resType))
4263+
case _ =>
4264+
mapOver(t)
42584265
val resultAlreadyConstrained = pt1.isInstanceOf[MethodOrPoly]
42594266
if (!resultAlreadyConstrained) {
42604267
if ctx.typerState.isCommittable then
4261-
NoViewsAllowed.constrainResult(tree.symbol, wtp, pt1)
4262-
else constrainResult(tree.symbol, wtp, pt1)
4268+
NoViewsAllowed.constrainResult(tree.symbol, wtp.resultType, tm(approxRes))
4269+
else constrainResult(tree.symbol, wtp.resultType, tm(approxRes))
42634270
}
42644271
}
42654272
}

0 commit comments

Comments
 (0)