@@ -34,20 +34,20 @@ object TypeApplications {
34
34
* @param tycon C
35
35
*/
36
36
object EtaExpansion {
37
- def apply (tycon : Type )(implicit ctx : Context ): Type = {
37
+ def apply (tycon : Type )(using Context ): Type = {
38
38
assert(tycon.typeParams.nonEmpty, tycon)
39
39
tycon.EtaExpand (tycon.typeParamSymbols)
40
40
}
41
41
42
- def unapply (tp : Type )(implicit ctx : Context ): Option [TypeRef ] = tp match {
42
+ def unapply (tp : Type )(using Context ): Option [TypeRef ] = tp match {
43
43
case tp @ HKTypeLambda (tparams, AppliedType (fn : TypeRef , args)) if (args == tparams.map(_.paramRef)) => Some (fn)
44
44
case _ => None
45
45
}
46
46
}
47
47
48
48
/** Adapt all arguments to possible higher-kinded type parameters using etaExpandIfHK
49
49
*/
50
- def EtaExpandIfHK (tparams : List [TypeParamInfo ], args : List [Type ])(implicit ctx : Context ): List [Type ] =
50
+ def EtaExpandIfHK (tparams : List [TypeParamInfo ], args : List [Type ])(using Context ): List [Type ] =
51
51
if (tparams.isEmpty) args
52
52
else args.zipWithConserve(tparams)((arg, tparam) => arg.EtaExpandIfHK (tparam.paramInfoOrCompleter))
53
53
@@ -86,7 +86,7 @@ object TypeApplications {
86
86
* result type. Using this mode, we can guarantee that `appliedTo` will never
87
87
* produce a higher-kinded application with a type lambda as type constructor.
88
88
*/
89
- class Reducer (tycon : TypeLambda , args : List [Type ])(implicit ctx : Context ) extends TypeMap {
89
+ class Reducer (tycon : TypeLambda , args : List [Type ])(using Context ) extends TypeMap {
90
90
private var available = (0 until args.length).toSet
91
91
var allReplaced : Boolean = true
92
92
def hasWildcardArg (p : TypeParamRef ): Boolean =
@@ -143,7 +143,7 @@ class TypeApplications(val self: Type) extends AnyVal {
143
143
* For a refinement type, the type parameters of its parent, dropping
144
144
* any type parameter that is-rebound by the refinement.
145
145
*/
146
- final def typeParams (implicit ctx : Context ): List [TypeParamInfo ] = {
146
+ final def typeParams (using Context ): List [TypeParamInfo ] = {
147
147
record(" typeParams" )
148
148
def isTrivial (prefix : Type , tycon : Symbol ) = prefix match {
149
149
case prefix : ThisType =>
@@ -184,22 +184,22 @@ class TypeApplications(val self: Type) extends AnyVal {
184
184
}
185
185
186
186
/** If `self` is a higher-kinded type, its type parameters, otherwise Nil */
187
- final def hkTypeParams (implicit ctx : Context ): List [TypeParamInfo ] =
187
+ final def hkTypeParams (using Context ): List [TypeParamInfo ] =
188
188
if (isLambdaSub) typeParams else Nil
189
189
190
190
/** If `self` is a generic class, its type parameter symbols, otherwise Nil */
191
- final def typeParamSymbols (implicit ctx : Context ): List [TypeSymbol ] = typeParams match {
191
+ final def typeParamSymbols (using Context ): List [TypeSymbol ] = typeParams match {
192
192
case (_ : Symbol ) :: _ =>
193
193
assert(typeParams.forall(_.isInstanceOf [Symbol ]))
194
194
typeParams.asInstanceOf [List [TypeSymbol ]]
195
195
case _ => Nil
196
196
}
197
197
198
198
/** Is self type bounded by a type lambda or AnyKind? */
199
- def isLambdaSub (implicit ctx : Context ): Boolean = hkResult.exists
199
+ def isLambdaSub (using Context ): Boolean = hkResult.exists
200
200
201
201
/** Is self type of kind "*"? */
202
- def hasSimpleKind (implicit ctx : Context ): Boolean =
202
+ def hasSimpleKind (using Context ): Boolean =
203
203
typeParams.isEmpty && ! self.hasAnyKind || {
204
204
val alias = self.dealias
205
205
(alias ne self) && alias.hasSimpleKind
@@ -208,7 +208,7 @@ class TypeApplications(val self: Type) extends AnyVal {
208
208
/** If self type is higher-kinded, its result type, otherwise NoType.
209
209
* Note: The hkResult of an any-kinded type is again AnyKind.
210
210
*/
211
- def hkResult (implicit ctx : Context ): Type = self.dealias match {
211
+ def hkResult (using Context ): Type = self.dealias match {
212
212
case self : TypeRef =>
213
213
if (self.symbol == defn.AnyKindClass ) self else self.info.hkResult
214
214
case self : AppliedType =>
@@ -227,7 +227,7 @@ class TypeApplications(val self: Type) extends AnyVal {
227
227
/** Do self and other have the same kinds (not counting bounds and variances)?
228
228
* Note: An any-kinded type "has the same kind" as any other type.
229
229
*/
230
- def hasSameKindAs (other : Type )(implicit ctx : Context ): Boolean = {
230
+ def hasSameKindAs (other : Type )(using Context ): Boolean = {
231
231
def isAnyKind (tp : Type ) = tp match {
232
232
case tp : TypeRef => tp.symbol == defn.AnyKindClass
233
233
case _ => false
@@ -245,7 +245,7 @@ class TypeApplications(val self: Type) extends AnyVal {
245
245
}
246
246
247
247
/** Dealias type if it can be done without forcing the TypeRef's info */
248
- def safeDealias (implicit ctx : Context ): Type = self match {
248
+ def safeDealias (using Context ): Type = self match {
249
249
case self : TypeRef if self.denot.exists && self.symbol.isAliasType =>
250
250
self.superType.stripTypeVar.safeDealias
251
251
case _ =>
@@ -255,16 +255,16 @@ class TypeApplications(val self: Type) extends AnyVal {
255
255
/** Convert a type constructor `TC` which has type parameters `X1, ..., Xn`
256
256
* to `[X1, ..., Xn] -> TC[X1, ..., Xn]`.
257
257
*/
258
- def EtaExpand (tparams : List [TypeParamInfo ])(implicit ctx : Context ): Type =
258
+ def EtaExpand (tparams : List [TypeParamInfo ])(using Context ): Type =
259
259
HKTypeLambda .fromParams(tparams, self.appliedTo(tparams.map(_.paramRef)))
260
260
// .ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
261
261
262
262
/** If self is not lambda-bound, eta expand it. */
263
- def ensureLambdaSub (implicit ctx : Context ): Type =
263
+ def ensureLambdaSub (using Context ): Type =
264
264
if (isLambdaSub) self else EtaExpansion (self)
265
265
266
266
/** Eta expand if `self` is a (non-lambda) class reference and `bound` is a higher-kinded type */
267
- def EtaExpandIfHK (bound : Type )(implicit ctx : Context ): Type = {
267
+ def EtaExpandIfHK (bound : Type )(using Context ): Type = {
268
268
val hkParams = bound.hkTypeParams
269
269
if (hkParams.isEmpty) self
270
270
else self match {
@@ -282,7 +282,7 @@ class TypeApplications(val self: Type) extends AnyVal {
282
282
* @param self = `T`
283
283
* @param args = `U1,...,Un`
284
284
*/
285
- final def appliedTo (args : List [Type ])(implicit ctx : Context ): Type = {
285
+ final def appliedTo (args : List [Type ])(using Context ): Type = {
286
286
record(" appliedTo" )
287
287
val typParams = self.typeParams
288
288
val stripped = self.stripTypeVar
@@ -347,18 +347,18 @@ class TypeApplications(val self: Type) extends AnyVal {
347
347
}
348
348
}
349
349
350
- final def appliedTo (arg : Type )(implicit ctx : Context ): Type = appliedTo(arg :: Nil )
351
- final def appliedTo (arg1 : Type , arg2 : Type )(implicit ctx : Context ): Type = appliedTo(arg1 :: arg2 :: Nil )
350
+ final def appliedTo (arg : Type )(using Context ): Type = appliedTo(arg :: Nil )
351
+ final def appliedTo (arg1 : Type , arg2 : Type )(using Context ): Type = appliedTo(arg1 :: arg2 :: Nil )
352
352
353
- final def applyIfParameterized (args : List [Type ])(implicit ctx : Context ): Type =
353
+ final def applyIfParameterized (args : List [Type ])(using Context ): Type =
354
354
if (typeParams.nonEmpty) appliedTo(args) else self
355
355
356
356
/** A cycle-safe version of `appliedTo` where computing type parameters do not force
357
357
* the typeconstructor. Instead, if the type constructor is completing, we make
358
358
* up hk type parameters matching the arguments. This is needed when unpickling
359
359
* Scala2 files such as `scala.collection.generic.Mapfactory`.
360
360
*/
361
- final def safeAppliedTo (args : List [Type ])(implicit ctx : Context ): Type = self match {
361
+ final def safeAppliedTo (args : List [Type ])(using Context ): Type = self match {
362
362
case self : TypeRef if ! self.symbol.isClass && self.symbol.isCompleting =>
363
363
AppliedType (self, args)
364
364
case _ =>
@@ -369,7 +369,7 @@ class TypeApplications(val self: Type) extends AnyVal {
369
369
* A (possible lambda abstracted) match type is turned into a match alias.
370
370
* Every other type is turned into a type alias
371
371
*/
372
- final def toBounds (implicit ctx : Context ): TypeBounds = self match {
372
+ final def toBounds (using Context ): TypeBounds = self match {
373
373
case self : TypeBounds => self // this can happen for wildcard args
374
374
case _ => if (self.isMatch) MatchAlias (self) else TypeAlias (self)
375
375
}
@@ -378,7 +378,7 @@ class TypeApplications(val self: Type) extends AnyVal {
378
378
* `from` and `to` must be static classes, both with one type parameter, and the same variance.
379
379
* Do the same for by name types => From[T] and => To[T]
380
380
*/
381
- def translateParameterized (from : ClassSymbol , to : ClassSymbol , wildcardArg : Boolean = false )(implicit ctx : Context ): Type = self match {
381
+ def translateParameterized (from : ClassSymbol , to : ClassSymbol , wildcardArg : Boolean = false )(using Context ): Type = self match {
382
382
case self @ ExprType (tp) =>
383
383
self.derivedExprType(tp.translateParameterized(from, to))
384
384
case _ =>
@@ -439,37 +439,37 @@ class TypeApplications(val self: Type) extends AnyVal {
439
439
* otherwise return Nil.
440
440
* Existential types in arguments are returned as TypeBounds instances.
441
441
*/
442
- final def argInfos (implicit ctx : Context ): List [Type ] = self.stripTypeVar.stripAnnots match {
442
+ final def argInfos (using Context ): List [Type ] = self.stripTypeVar.stripAnnots match {
443
443
case AppliedType (tycon, args) => args
444
444
case _ => Nil
445
445
}
446
446
447
447
/** Argument types where existential types in arguments are disallowed */
448
- def argTypes (implicit ctx : Context ): List [Type ] = argInfos mapConserve noBounds
448
+ def argTypes (using Context ): List [Type ] = argInfos mapConserve noBounds
449
449
450
450
/** Argument types where existential types in arguments are approximated by their lower bound */
451
- def argTypesLo (implicit ctx : Context ): List [Type ] = argInfos.mapConserve(_.loBound)
451
+ def argTypesLo (using Context ): List [Type ] = argInfos.mapConserve(_.loBound)
452
452
453
453
/** Argument types where existential types in arguments are approximated by their upper bound */
454
- def argTypesHi (implicit ctx : Context ): List [Type ] = argInfos.mapConserve(_.hiBound)
454
+ def argTypesHi (using Context ): List [Type ] = argInfos.mapConserve(_.hiBound)
455
455
456
456
/** If this is the image of a type argument; recover the type argument,
457
457
* otherwise NoType.
458
458
*/
459
- final def argInfo (implicit ctx : Context ): Type = self match {
459
+ final def argInfo (using Context ): Type = self match {
460
460
case self : TypeAlias => self.alias
461
461
case self : TypeBounds => self
462
462
case _ => NoType
463
463
}
464
464
465
465
/** If this is a type alias, its underlying type, otherwise the type itself */
466
- def dropAlias (implicit ctx : Context ): Type = self match {
466
+ def dropAlias (using Context ): Type = self match {
467
467
case TypeAlias (alias) => alias
468
468
case _ => self
469
469
}
470
470
471
471
/** The element type of a sequence or array */
472
- def elemType (implicit ctx : Context ): Type = self.widenDealias match {
472
+ def elemType (using Context ): Type = self.widenDealias match {
473
473
case defn.ArrayOf (elemtp) => elemtp
474
474
case JavaArrayType (elemtp) => elemtp
475
475
case _ => self.baseType(defn.SeqClass ).argInfos.headOption.getOrElse(NoType )
0 commit comments