Skip to content

Commit ce08e50

Browse files
committed
Drop ConstrainResultDeep mode
1 parent 8cca3a0 commit ce08e50

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object ProtoTypes {
9292
case mt: MethodType =>
9393
constrainResult(resultTypeApprox(mt), pt.resultType)
9494
&& {
95-
if ctx.mode.is(Mode.ConstrainResultDeep) then
95+
if pt.constrainResultDeep then
9696
if mt.isImplicitMethod == (pt.applyKind == ApplyKind.Using) then
9797
val tpargs = pt.args.lazyZip(mt.paramInfos).map(pt.typedArg)
9898
tpargs.tpes.corresponds(mt.paramInfos)(_ <:< _)
@@ -300,9 +300,21 @@ object ProtoTypes {
300300
/** A prototype for expressions that appear in function position
301301
*
302302
* [](args): resultType
303+
*
304+
* @param args The untyped arguments to which the function is applied
305+
* @param resType The expeected result type
306+
* @param typer The typer to use for typing the arguments
307+
* @param applyKind The kind of application (regular/using/tupled infix operand)
308+
* @param state The state object to use for tracking the changes to this prototype
309+
* @param constrainResultDeep
310+
* A flag to indicate that constrainResult on this prototype
311+
* should typechec and compare the arguments.
303312
*/
304-
case class FunProto(args: List[untpd.Tree], resType: Type)(typer: Typer,
305-
override val applyKind: ApplyKind, state: FunProtoState = new FunProtoState)(using protoCtx: Context)
313+
case class FunProto(args: List[untpd.Tree], resType: Type)(
314+
typer: Typer,
315+
override val applyKind: ApplyKind,
316+
state: FunProtoState = new FunProtoState,
317+
val constrainResultDeep: Boolean = false)(using protoCtx: Context)
306318
extends UncachedGroundType with ApplyingProto with FunOrPolyProto {
307319
override def resultType(using Context): Type = resType
308320

@@ -314,8 +326,16 @@ object ProtoTypes {
314326
typer.isApplicableType(tp, args, resultType, keepConstraint && !args.exists(isPoly))
315327
}
316328

317-
def derivedFunProto(args: List[untpd.Tree] = this.args, resultType: Type, typer: Typer = this.typer): FunProto =
318-
if ((args eq this.args) && (resultType eq this.resultType) && (typer eq this.typer)) this
329+
def derivedFunProto(
330+
args: List[untpd.Tree] = this.args,
331+
resultType: Type = this.resultType,
332+
typer: Typer = this.typer,
333+
constrainResultDeep: Boolean = this.constrainResultDeep): FunProto =
334+
if (args eq this.args)
335+
&& (resultType eq this.resultType)
336+
&& (typer eq this.typer)
337+
&& constrainResultDeep == this.constrainResultDeep
338+
then this
319339
else new FunProto(args, resultType)(typer, applyKind)
320340

321341
/** @return True if all arguments have types.
@@ -444,10 +464,10 @@ object ProtoTypes {
444464
ta(ta.foldOver(x, typedArgs().tpes), resultType)
445465

446466
override def deepenProto(using Context): FunProto =
447-
derivedFunProto(args, resultType.deepenProto, typer)
467+
derivedFunProto(args, resultType.deepenProto)
448468

449469
override def deepenProtoTrans(using Context): FunProto =
450-
derivedFunProto(args, resultType.deepenProtoTrans, typer)
470+
derivedFunProto(args, resultType.deepenProtoTrans, constrainResultDeep = true)
451471

452472
override def withContext(newCtx: Context): ProtoType =
453473
if newCtx `eq` protoCtx then this

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,10 +3174,7 @@ class Typer extends Namer
31743174
arg.tpe match
31753175
case failed: AmbiguousImplicits =>
31763176
val pt1 = pt.deepenProtoTrans
3177-
if (pt1 `ne` pt) && (pt1 ne sharpenedPt)
3178-
&& withMode(Mode.ConstrainResultDeep)(
3179-
constrainResult(tree.symbol, wtp, pt1)
3180-
)
3177+
if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && constrainResult(tree.symbol, wtp, pt1)
31813178
then implicitArgs(formals, argIndex, pt1)
31823179
else arg :: implicitArgs(formals1, argIndex + 1, pt1)
31833180
case failed: SearchFailureType =>

0 commit comments

Comments
 (0)