@@ -55,7 +55,7 @@ object ProtoTypes {
55
55
val normTp = normalize(tp, pt)
56
56
isCompatible(normTp, pt) || pt.isRef(defn.UnitClass ) && normTp.isParameterless
57
57
58
- if keepConstraint || ctx.mode.is( Mode . ConstrainResultDeep ) then
58
+ if keepConstraint then
59
59
tp.widenSingleton match
60
60
case poly : PolyType =>
61
61
val newctx = ctx.fresh.setNewTyperState()
@@ -88,19 +88,18 @@ object ProtoTypes {
88
88
val savedConstraint = ctx.typerState.constraint
89
89
val res = pt.widenExpr match {
90
90
case pt : FunProto =>
91
- mt match {
91
+ mt match
92
92
case mt : MethodType =>
93
93
constrainResult(resultTypeApprox(mt), pt.resultType)
94
94
&& {
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)(_ <:< _)
100
100
else true
101
101
}
102
102
case _ => true
103
- }
104
103
case _ : ValueTypeOrProto if ! disregardProto(pt) =>
105
104
necessarilyCompatible(mt, pt)
106
105
case pt : WildcardType if pt.optBounds.exists =>
@@ -300,9 +299,21 @@ object ProtoTypes {
300
299
/** A prototype for expressions that appear in function position
301
300
*
302
301
* [](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.
303
311
*/
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 )
306
317
extends UncachedGroundType with ApplyingProto with FunOrPolyProto {
307
318
override def resultType (using Context ): Type = resType
308
319
@@ -314,9 +325,17 @@ object ProtoTypes {
314
325
typer.isApplicableType(tp, args, resultType, keepConstraint && ! args.exists(isPoly))
315
326
}
316
327
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)
320
339
321
340
/** @return True if all arguments have types.
322
341
*/
@@ -444,10 +463,10 @@ object ProtoTypes {
444
463
ta(ta.foldOver(x, typedArgs().tpes), resultType)
445
464
446
465
override def deepenProto (using Context ): FunProto =
447
- derivedFunProto(args, resultType.deepenProto, typer )
466
+ derivedFunProto(args, resultType.deepenProto)
448
467
449
468
override def deepenProtoTrans (using Context ): FunProto =
450
- derivedFunProto(args, resultType.deepenProtoTrans, typer )
469
+ derivedFunProto(args, resultType.deepenProtoTrans, constrainResultDeep = true )
451
470
452
471
override def withContext (newCtx : Context ): ProtoType =
453
472
if newCtx `eq` protoCtx then this
0 commit comments