@@ -55,7 +55,7 @@ object ProtoTypes {
5555 val normTp = normalize(tp, pt)
5656 isCompatible(normTp, pt) || pt.isRef(defn.UnitClass ) && normTp.isParameterless
5757
58- if keepConstraint || ctx.mode.is( Mode . ConstrainResultDeep ) then
58+ if keepConstraint then
5959 tp.widenSingleton match
6060 case poly : PolyType =>
6161 val newctx = ctx.fresh.setNewTyperState()
@@ -88,19 +88,18 @@ object ProtoTypes {
8888 val savedConstraint = ctx.typerState.constraint
8989 val res = pt.widenExpr match {
9090 case pt : FunProto =>
91- mt match {
91+ mt match
9292 case mt : MethodType =>
9393 constrainResult(resultTypeApprox(mt), pt.resultType)
9494 && {
95- if ctx.mode.is( Mode . ConstrainResultDeep ) then
96- if mt.isImplicitMethod == (pt.applyKind == ApplyKind .Using ) then
97- val tpargs = pt.args.lazyZip(mt.paramInfos).map(pt.typedArg)
98- tpargs.tpes.corresponds (mt.paramInfos)(_ <:< _ )
99- else true
95+ if pt.constrainResultDeep
96+ && mt.isImplicitMethod == (pt.applyKind == ApplyKind .Using )
97+ then
98+ val tpargs = pt.args.lazyZip (mt.paramInfos).map(pt.typedArg )
99+ tpargs.tpes.corresponds(mt.paramInfos)(_ <:< _)
100100 else true
101101 }
102102 case _ => true
103- }
104103 case _ : ValueTypeOrProto if ! disregardProto(pt) =>
105104 necessarilyCompatible(mt, pt)
106105 case pt : WildcardType if pt.optBounds.exists =>
@@ -300,9 +299,21 @@ object ProtoTypes {
300299 /** A prototype for expressions that appear in function position
301300 *
302301 * [](args): resultType
302+ *
303+ * @param args The untyped arguments to which the function is applied
304+ * @param resType The expeected result type
305+ * @param typer The typer to use for typing the arguments
306+ * @param applyKind The kind of application (regular/using/tupled infix operand)
307+ * @param state The state object to use for tracking the changes to this prototype
308+ * @param constrainResultDeep
309+ * A flag to indicate that constrainResult on this prototype
310+ * should typecheck and compare the arguments.
303311 */
304- case class FunProto (args : List [untpd.Tree ], resType : Type )(typer : Typer ,
305- override val applyKind : ApplyKind , state : FunProtoState = new FunProtoState )(using protoCtx : Context )
312+ case class FunProto (args : List [untpd.Tree ], resType : Type )(
313+ typer : Typer ,
314+ override val applyKind : ApplyKind ,
315+ state : FunProtoState = new FunProtoState ,
316+ val constrainResultDeep : Boolean = false )(using protoCtx : Context )
306317 extends UncachedGroundType with ApplyingProto with FunOrPolyProto {
307318 override def resultType (using Context ): Type = resType
308319
@@ -314,9 +325,17 @@ object ProtoTypes {
314325 typer.isApplicableType(tp, args, resultType, keepConstraint && ! args.exists(isPoly))
315326 }
316327
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
319- else new FunProto (args, resultType)(typer, applyKind)
328+ def derivedFunProto (
329+ args : List [untpd.Tree ] = this .args,
330+ resultType : Type = this .resultType,
331+ typer : Typer = this .typer,
332+ constrainResultDeep : Boolean = this .constrainResultDeep): FunProto =
333+ if (args eq this .args)
334+ && (resultType eq this .resultType)
335+ && (typer eq this .typer)
336+ && constrainResultDeep == this .constrainResultDeep
337+ then this
338+ else new FunProto (args, resultType)(typer, applyKind, constrainResultDeep = constrainResultDeep)
320339
321340 /** @return True if all arguments have types.
322341 */
@@ -444,10 +463,10 @@ object ProtoTypes {
444463 ta(ta.foldOver(x, typedArgs().tpes), resultType)
445464
446465 override def deepenProto (using Context ): FunProto =
447- derivedFunProto(args, resultType.deepenProto, typer )
466+ derivedFunProto(args, resultType.deepenProto)
448467
449468 override def deepenProtoTrans (using Context ): FunProto =
450- derivedFunProto(args, resultType.deepenProtoTrans, typer )
469+ derivedFunProto(args, resultType.deepenProtoTrans, constrainResultDeep = true )
451470
452471 override def withContext (newCtx : Context ): ProtoType =
453472 if newCtx `eq` protoCtx then this
0 commit comments