@@ -726,41 +726,39 @@ object ProtoTypes {
726
726
tl : TypeLambda , owningTree : untpd.Tree ,
727
727
alwaysAddTypeVars : Boolean ,
728
728
nestingLevel : Int = ctx.nestingLevel
729
- ): (TypeLambda , List [TypeTree ]) = {
729
+ ): (TypeLambda , List [TypeVar ]) = {
730
730
val state = ctx.typerState
731
731
val addTypeVars = alwaysAddTypeVars || ! owningTree.isEmpty
732
732
if (tl.isInstanceOf [PolyType ])
733
733
assert(! ctx.typerState.isCommittable || addTypeVars,
734
734
s " inconsistent: no typevars were added to committable constraint ${state.constraint}" )
735
735
// hk type lambdas can be added to constraints without typevars during match reduction
736
736
737
- def newTypeVars (tl : TypeLambda ): List [TypeTree ] =
738
- for (paramRef <- tl.paramRefs)
739
- yield {
740
- val tt = InferredTypeTree ().withSpan(owningTree.span)
737
+ def newTypeVars (tl : TypeLambda ): List [TypeVar ] =
738
+ for paramRef <- tl.paramRefs
739
+ yield
741
740
val tvar = TypeVar (paramRef, state, nestingLevel)
742
741
state.ownedVars += tvar
743
- tt.withType(tvar)
744
- }
742
+ tvar
745
743
746
744
val added = state.constraint.ensureFresh(tl)
747
- val tvars = if ( addTypeVars) newTypeVars(added) else Nil
748
- TypeComparer .addToConstraint(added, tvars.tpes. asInstanceOf [ List [ TypeVar ]] )
745
+ val tvars = if addTypeVars then newTypeVars(added) else Nil
746
+ TypeComparer .addToConstraint(added, tvars)
749
747
(added, tvars)
750
748
}
751
749
752
- def constrained (tl : TypeLambda , owningTree : untpd.Tree )(using Context ): (TypeLambda , List [TypeTree ]) =
750
+ def constrained (tl : TypeLambda , owningTree : untpd.Tree )(using Context ): (TypeLambda , List [TypeVar ]) =
753
751
constrained(tl, owningTree,
754
752
alwaysAddTypeVars = tl.isInstanceOf [PolyType ] && ctx.typerState.isCommittable)
755
753
756
- /** Same as `constrained(tl, EmptyTree)`, but returns just the created type lambda */
757
- def constrained (tl : TypeLambda )(using Context ): TypeLambda =
758
- constrained(tl, EmptyTree )._1
754
+ /** Same as `constrained(tl, EmptyTree, alwaysAddTypeVars = true )`, but returns just the created type vars. */
755
+ def constrained (tl : TypeLambda )(using Context ): List [ TypeVar ] =
756
+ constrained(tl, EmptyTree , alwaysAddTypeVars = true )._2
759
757
760
758
/** Instantiate `tl` with fresh type variables added to the constraint. */
761
759
def instantiateWithTypeVars (tl : TypeLambda )(using Context ): Type =
762
- val targs = constrained(tl, ast.tpd. EmptyTree , alwaysAddTypeVars = true )._2
763
- tl.instantiate(targs.tpes )
760
+ val tvars = constrained(tl)
761
+ tl.instantiate(tvars )
764
762
765
763
/** A fresh type variable added to the current constraint.
766
764
* @param bounds The initial bounds of the variable
@@ -779,7 +777,7 @@ object ProtoTypes {
779
777
pt => bounds :: Nil ,
780
778
pt => represents.orElse(defn.AnyType ))
781
779
constrained(poly, untpd.EmptyTree , alwaysAddTypeVars = true , nestingLevel)
782
- ._2.head.tpe. asInstanceOf [ TypeVar ]
780
+ ._2.head
783
781
784
782
/** If `param` was created using `newTypeVar(..., represents = X)`, returns X.
785
783
* This is used in:
0 commit comments