@@ -244,7 +244,7 @@ object ProtoTypes {
244244 * [](args): resultType
245245 */
246246 case class FunProto (args : List [untpd.Tree ], resType : Type )(typer : Typer ,
247- override val isContextual : Boolean , state : FunProtoState = new FunProtoState )(implicit ctx : Context )
247+ override val isContextual : Boolean , state : FunProtoState = new FunProtoState )(implicit val ctx : Context )
248248 extends UncachedGroundType with ApplyingProto with FunOrPolyProto {
249249 override def resultType (implicit ctx : Context ): Type = resType
250250
@@ -298,13 +298,26 @@ object ProtoTypes {
298298
299299 /** The typed arguments. This takes any arguments already typed using
300300 * `typedArg` into account.
301+ *
302+ * Arguments are typechecked in the typerState where the FunProto was created.
303+ * However, any constraint changes are also propagated to the currently passed
304+ * context.
305+ *
301306 */
302- def unforcedTypedArgs : List [Tree ] =
307+ def unforcedTypedArgs ( implicit ctx : Context ) : List [Tree ] =
303308 if (state.typedArgs.size == args.length) state.typedArgs
304309 else {
305- val args1 = args.mapconserve(cacheTypedArg(_, typer.typed(_), force = false ))
306- if (! args1.exists(arg => isUndefined(arg.tpe))) state.typedArgs = args1
307- args1
310+ val prevConstraint = this .ctx.typerState.constraint
311+
312+ try {
313+ implicit val ctx = this .ctx
314+ val args1 = args.mapconserve(cacheTypedArg(_, typer.typed(_), force = false ))
315+ if (! args1.exists(arg => isUndefined(arg.tpe))) state.typedArgs = args1
316+ args1
317+ }
318+ finally
319+ if (this .ctx.typerState.constraint ne prevConstraint)
320+ ctx.typerState.mergeConstraintWith(this .ctx.typerState)
308321 }
309322
310323 /** Type single argument and remember the unadapted result in `myTypedArg`.
@@ -372,7 +385,7 @@ object ProtoTypes {
372385 * [](args): resultType, where args are known to be typed
373386 */
374387 class FunProtoTyped (args : List [tpd.Tree ], resultType : Type )(typer : Typer , isContextual : Boolean )(implicit ctx : Context ) extends FunProto (args, resultType)(typer, isContextual)(ctx) {
375- override def unforcedTypedArgs : List [tpd.Tree ] = args
388+ override def unforcedTypedArgs ( implicit ctx : Context ) : List [tpd.Tree ] = args
376389 override def withContext (ctx : Context ): FunProtoTyped = this
377390 }
378391
0 commit comments