@@ -377,9 +377,10 @@ object ProtoTypes {
377
377
* Also, if `owningTree` is non-empty, add a type variable for each parameter.
378
378
* @return The added type lambda, and the list of created type variables.
379
379
*/
380
- def constrained (tl : TypeLambda , owningTree : untpd.Tree )(implicit ctx : Context ): (TypeLambda , List [TypeTree ]) = {
380
+ def constrained (tl : TypeLambda , owningTree : untpd.Tree , alwaysAddTypeVars : Boolean = false )(implicit ctx : Context ): (TypeLambda , List [TypeTree ]) = {
381
381
val state = ctx.typerState
382
- assert(! (ctx.typerState.isCommittable && owningTree.isEmpty),
382
+ val addTypeVars = alwaysAddTypeVars || ! owningTree.isEmpty
383
+ assert(! (ctx.typerState.isCommittable && ! addTypeVars),
383
384
s " inconsistent: no typevars were added to committable constraint ${state.constraint}" )
384
385
385
386
def newTypeVars (tl : TypeLambda ): List [TypeTree ] =
@@ -392,21 +393,21 @@ object ProtoTypes {
392
393
val added =
393
394
if (state.constraint contains tl) tl.newLikeThis(tl.paramNames, tl.paramInfos, tl.resultType)
394
395
else tl
395
- val tvars = if (owningTree.isEmpty) Nil else newTypeVars(added)
396
+ val tvars = if (addTypeVars) newTypeVars(added) else Nil
396
397
ctx.typeComparer.addToConstraint(added, tvars.tpes.asInstanceOf [List [TypeVar ]])
397
398
(added, tvars)
398
399
}
399
400
400
401
/** Same as `constrained(tl, EmptyTree)`, but returns just the created type lambda */
401
402
def constrained (tl : TypeLambda )(implicit ctx : Context ): TypeLambda = constrained(tl, EmptyTree )._1
402
403
403
- /** Create a new TypeParamRef that represents a dependent method parameter singleton */
404
- def newDepTypeParamRef (tp : Type )(implicit ctx : Context ): TypeParamRef = {
404
+ /** Create a new TypeVar that represents a dependent method parameter singleton */
405
+ def newDepTypeVar (tp : Type )(implicit ctx : Context ): TypeVar = {
405
406
val poly = PolyType (DepParamName .fresh().toTypeName :: Nil )(
406
407
pt => TypeBounds .upper(AndType (tp, defn.SingletonType )) :: Nil ,
407
408
pt => defn.AnyType )
408
- ctx.typeComparer.addToConstraint (poly, Nil )
409
- TypeParamRef (poly, 0 )
409
+ constrained (poly, untpd. EmptyTree , alwaysAddTypeVars = true )
410
+ ._2.head.tpe. asInstanceOf [ TypeVar ]
410
411
}
411
412
412
413
/** The result type of `mt`, where all references to parameters of `mt` are
@@ -415,7 +416,7 @@ object ProtoTypes {
415
416
def resultTypeApprox (mt : MethodType )(implicit ctx : Context ): Type =
416
417
if (mt.isDependent) {
417
418
def replacement (tp : Type ) =
418
- if (ctx.mode.is(Mode .TypevarsMissContext )) WildcardType else newDepTypeParamRef (tp)
419
+ if (ctx.mode.is(Mode .TypevarsMissContext )) WildcardType else newDepTypeVar (tp)
419
420
mt.resultType.substParams(mt, mt.paramInfos.map(replacement))
420
421
}
421
422
else mt.resultType
0 commit comments