@@ -427,7 +427,7 @@ object Types {
427
427
def isContextualMethod : Boolean = false
428
428
429
429
/** Is this a MethodType for which the parameters will not be used? */
430
- def hasErasedParams : Boolean = false
430
+ def hasErasedParams ( using Context ) : Boolean = false
431
431
432
432
/** Is this a match type or a higher-kinded abstraction of one?
433
433
*/
@@ -1182,7 +1182,8 @@ object Types {
1182
1182
1183
1183
/** Remove all AnnotatedTypes wrapping this type.
1184
1184
*/
1185
- def stripAnnots (using Context ): Type = this
1185
+ def stripAnnots (keep : Annotation => Context ?=> Boolean )(using Context ): Type = this
1186
+ final def stripAnnots (using Context ): Type = stripAnnots(_ => false )
1186
1187
1187
1188
/** Strip TypeVars and Annotation and CapturingType wrappers */
1188
1189
def stripped (using Context ): Type = this
@@ -1843,14 +1844,13 @@ object Types {
1843
1844
case mt : MethodType if ! mt.isParamDependent =>
1844
1845
val formals1 = if (dropLast == 0 ) mt.paramInfos else mt.paramInfos dropRight dropLast
1845
1846
val isContextual = mt.isContextualMethod && ! ctx.erasedTypes
1846
- val erasedParams = (if ! ctx.erasedTypes then mt.erasedParams else List .fill(mt.paramInfos.size) { false }).dropRight(dropLast)
1847
1847
val result1 = mt.nonDependentResultApprox match {
1848
1848
case res : MethodType => res.toFunctionType(isJava)
1849
1849
case res => res
1850
1850
}
1851
1851
val funType = defn.FunctionOf (
1852
1852
formals1 mapConserve (_.translateFromRepeated(toArray = isJava)),
1853
- result1, isContextual, erasedParams )
1853
+ result1, isContextual)
1854
1854
if alwaysDependent || mt.isResultDependent then RefinedType (funType, nme.apply, mt)
1855
1855
else funType
1856
1856
}
@@ -3623,7 +3623,7 @@ object Types {
3623
3623
3624
3624
def companion : LambdaTypeCompanion [ThisName , PInfo , This ]
3625
3625
3626
- def erasedParams = List .fill(paramInfos.size)(false )
3626
+ def erasedParams ( using Context ) = List .fill(paramInfos.size)(false )
3627
3627
3628
3628
/** The type `[tparams := paramRefs] tp`, where `tparams` can be
3629
3629
* either a list of type parameter symbols or a list of lambda parameters
@@ -3913,38 +3913,14 @@ object Types {
3913
3913
def companion : MethodTypeCompanion
3914
3914
3915
3915
final override def isImplicitMethod : Boolean =
3916
- companion.eq(ImplicitMethodType ) ||
3917
- companion.isInstanceOf [ErasedImplicitMethodType ] ||
3918
- isContextualMethod
3919
- final override def hasErasedParams : Boolean =
3920
- companion.isInstanceOf [ErasedMethodCompanion ]
3916
+ companion.eq(ImplicitMethodType ) || isContextualMethod
3917
+ final override def hasErasedParams (using Context ): Boolean =
3918
+ erasedParams.contains(true )
3921
3919
final override def isContextualMethod : Boolean =
3922
- companion.eq(ContextualMethodType ) ||
3923
- companion.isInstanceOf [ErasedContextualMethodType ]
3924
-
3925
- override def erasedParams : List [Boolean ] = companion match
3926
- case c : ErasedMethodCompanion => c.erasedParams
3927
- case _ => super .erasedParams
3928
-
3929
- // Mark erased classes as erased parameters as well.
3930
- def markErasedClasses (using Context ): MethodType =
3931
- val isErasedClass = paramInfos.map(_.isErasedClass)
3932
- if isErasedClass.contains(true ) then companion match
3933
- case c : ErasedMethodCompanion =>
3934
- val erasedParams = c.erasedParams.zipWithConserve(isErasedClass) { (a, b) => a || b }
3935
- if erasedParams == c.erasedParams then this
3936
- else MethodType .companion(
3937
- isContextual = isContextualMethod,
3938
- isImplicit = isImplicitMethod,
3939
- erasedParams = erasedParams
3940
- )(paramNames)(paramInfosExp, resultTypeExp)
3941
- case _ =>
3942
- MethodType .companion(
3943
- isContextual = isContextualMethod,
3944
- isImplicit = isImplicitMethod,
3945
- erasedParams = isErasedClass
3946
- )(paramNames)(paramInfosExp, resultTypeExp)
3947
- else this
3920
+ companion.eq(ContextualMethodType )
3921
+
3922
+ override def erasedParams (using Context ): List [Boolean ] =
3923
+ paramInfos.map(p => p.hasAnnotation(defn.ErasedParamAnnot ) || p.isErasedClass)
3948
3924
3949
3925
protected def prefixString : String = companion.prefixString
3950
3926
}
@@ -4041,7 +4017,7 @@ object Types {
4041
4017
tl => tl.integrate(params, resultType))
4042
4018
end fromSymbols
4043
4019
4044
- final def apply (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(using Context ): MethodType =
4020
+ def apply (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(using Context ): MethodType =
4045
4021
checkValid(unique(new CachedMethodType (paramNames)(paramInfosExp, resultTypeExp, self)))
4046
4022
4047
4023
def checkValid (mt : MethodType )(using Context ): mt.type = {
@@ -4056,25 +4032,14 @@ object Types {
4056
4032
}
4057
4033
4058
4034
object MethodType extends MethodTypeCompanion (" MethodType" ) {
4059
- def companion (isContextual : Boolean = false , isImplicit : Boolean = false , erasedParams : List [Boolean ] = Nil ): MethodTypeCompanion =
4060
- val hasErased = erasedParams.contains(true )
4061
- if (isContextual)
4062
- if (hasErased) ErasedContextualMethodType (erasedParams) else ContextualMethodType
4063
- else if (isImplicit)
4064
- if (hasErased) ErasedImplicitMethodType (erasedParams) else ImplicitMethodType
4065
- else
4066
- if (hasErased) ErasedMethodType (erasedParams) else MethodType
4035
+ def companion (isContextual : Boolean = false , isImplicit : Boolean = false ): MethodTypeCompanion =
4036
+ if (isContextual) ContextualMethodType
4037
+ else if (isImplicit) ImplicitMethodType
4038
+ else MethodType
4067
4039
}
4068
- private def erasedMt (t : String , erasedParams : List [Boolean ]) =
4069
- s " Erased ${t}( ${erasedParams.map(if _ then " erased _" else " _" ).mkString(" , " )}) "
4070
- sealed abstract class ErasedMethodCompanion (prefixString : String , val erasedParams : List [Boolean ])
4071
- extends MethodTypeCompanion (erasedMt(prefixString, erasedParams))
4072
4040
4073
- class ErasedMethodType (erasedParams : List [Boolean ]) extends ErasedMethodCompanion (" MethodType" , erasedParams)
4074
4041
object ContextualMethodType extends MethodTypeCompanion (" ContextualMethodType" )
4075
- class ErasedContextualMethodType (erasedParams : List [Boolean ]) extends ErasedMethodCompanion (" ContextualMethodType" , erasedParams)
4076
4042
object ImplicitMethodType extends MethodTypeCompanion (" ImplicitMethodType" )
4077
- class ErasedImplicitMethodType (erasedParams : List [Boolean ]) extends ErasedMethodCompanion (" ImplicitMethodType" , erasedParams)
4078
4043
4079
4044
/** A ternary extractor for MethodType */
4080
4045
object MethodTpe {
@@ -5289,7 +5254,10 @@ object Types {
5289
5254
override def stripTypeVar (using Context ): Type =
5290
5255
derivedAnnotatedType(parent.stripTypeVar, annot)
5291
5256
5292
- override def stripAnnots (using Context ): Type = parent.stripAnnots
5257
+ override def stripAnnots (keep : Annotation => (Context ) ?=> Boolean )(using Context ): Type =
5258
+ val p = parent.stripAnnots(keep)
5259
+ if keep(annot) then derivedAnnotatedType(p, annot)
5260
+ else p
5293
5261
5294
5262
override def stripped (using Context ): Type = parent.stripped
5295
5263
0 commit comments