@@ -12,6 +12,7 @@ import collection.mutable
12
12
import reporting .*
13
13
import Checking .{checkNoPrivateLeaks , checkNoWildcard }
14
14
import cc .CaptureSet
15
+ import util .Property
15
16
import transform .Splicer
16
17
17
18
trait TypeAssigner {
@@ -273,33 +274,32 @@ trait TypeAssigner {
273
274
/** Substitute argument type `argType` for parameter `pref` in type `tp`,
274
275
* skolemizing the argument type if it is not stable and `pref` occurs in `tp`.
275
276
*/
276
- def safeSubstParam (tp : Type , pref : ParamRef , argType : Type )(using Context ): Type = {
277
+ def safeSubstParam (tp : Type , pref : ParamRef , argType : Type , arg : Tree | Null = null )(using Context ): Type = {
277
278
val tp1 = tp.substParam(pref, argType)
278
- if (( tp1 eq tp) || argType.isStable) tp1
279
+ if (tp1 eq tp) || argType.isStable then tp1
279
280
else tp.substParam(pref, SkolemType (argType.widen))
280
281
}
281
282
282
283
/** Substitute types of all arguments `args` for corresponding `params` in `tp`.
283
284
* The number of parameters `params` may exceed the number of arguments.
284
285
* In this case, only the common prefix is substituted.
285
286
*/
286
- def safeSubstParams (tp : Type , params : List [ParamRef ], argTypes : List [Type ])(using Context ): Type = argTypes match {
287
- case argType :: argTypes1 =>
288
- val tp1 = safeSubstParam(tp, params.head, argType )
289
- safeSubstParams(tp1, params.tail, argTypes1 )
287
+ def safeSubstParams (tp : Type , params : List [ParamRef ], args : List [Tree ])(using Context ): Type = args match
288
+ case arg :: args1 =>
289
+ val tp1 = safeSubstParam(tp, params.head, arg.tpe, arg )
290
+ safeSubstParams(tp1, params.tail, args1 )
290
291
case Nil =>
291
292
tp
292
- }
293
293
294
- def safeSubstMethodParams (mt : MethodType , argTypes : List [Type ])(using Context ): Type =
295
- if mt.isResultDependent then safeSubstParams(mt.resultType, mt.paramRefs, argTypes )
294
+ def safeSubstMethodParams (mt : MethodType , args : List [Tree ])(using Context ): Type =
295
+ if mt.isResultDependent then safeSubstParams(mt.resultType, mt.paramRefs, args )
296
296
else mt.resultType
297
297
298
298
def assignType (tree : untpd.Apply , fn : Tree , args : List [Tree ])(using Context ): Apply = {
299
299
val ownType = fn.tpe.widen match {
300
300
case fntpe : MethodType =>
301
301
if fntpe.paramInfos.hasSameLengthAs(args) || ctx.phase.prev.relaxedTyping then
302
- if fntpe.isResultDependent then safeSubstMethodParams(fntpe, args.tpes )
302
+ if fntpe.isResultDependent then safeSubstMethodParams(fntpe, args)
303
303
else fntpe.resultType // fast path optimization
304
304
else
305
305
val erroringPhase =
@@ -570,6 +570,12 @@ trait TypeAssigner {
570
570
}
571
571
572
572
object TypeAssigner extends TypeAssigner :
573
+
574
+ /** An attachment on an argument in an application indicating that the argument's
575
+ * type was converted to the given skolem type.
576
+ */
577
+ private [typer] val Skolemized = new Property .StickyKey [SkolemType ]
578
+
573
579
def seqLitType (tree : untpd.SeqLiteral , elemType : Type )(using Context ) = tree match
574
580
case tree : untpd.JavaSeqLiteral => defn.ArrayOf (elemType)
575
581
case _ => if ctx.erasedTypes then defn.SeqType else defn.SeqType .appliedTo(elemType)
0 commit comments