@@ -27,14 +27,13 @@ private[internal] trait TypeMaps {
27
27
import definitions ._
28
28
29
29
/** Normalize any type aliases within this type (@see Type#normalize).
30
- * Note that this depends very much on the call to "normalize", not "dealias",
31
- * so it is no longer carries the too-stealthy name "deAlias".
32
- */
30
+ * Note that this depends very much on the call to "normalize", not "dealias",
31
+ * so it no longer carries the too-stealthy name "deAlias".
32
+ */
33
33
object normalizeAliases extends TypeMap {
34
34
def apply (tp : Type ): Type = (tp match {
35
- case TypeRef (_, sym, _) if sym.isAliasType && tp.isHigherKinded => logResult(s " Normalized type alias function $tp" )(tp.normalize)
36
- case TypeRef (_, sym, _) if sym.isAliasType => tp.normalize
37
- case tp => tp
35
+ case TypeRef (_, sym, _) if sym.isAliasType => logResultIf(s " Normalized type alias function $tp" , (_ : Type ) => tp.isHigherKinded)(tp.normalize)
36
+ case tp => tp
38
37
}).mapOver(this )
39
38
}
40
39
@@ -98,10 +97,8 @@ private[internal] trait TypeMaps {
98
97
def keepAnnotation (annot : AnnotationInfo ) = annot matches TypeConstraintClass
99
98
}
100
99
101
- // todo. move these into scala.reflect.api
102
-
103
100
/** A prototype for mapping a function over all possible types
104
- */
101
+ */
105
102
abstract class TypeMap extends (Type => Type ) {
106
103
def apply (tp : Type ): Type
107
104
@@ -314,7 +311,7 @@ private[internal] trait TypeMaps {
314
311
*/
315
312
316
313
/** Used by existentialAbstraction.
317
- */
314
+ */
318
315
class ExistentialExtrapolation (tparams : List [Symbol ]) extends VariancedTypeMap {
319
316
private [this ] val occurCount = mutable.HashMap [Symbol , Int ]()
320
317
private [this ] val anyContains = new ContainsAnyKeyCollector (occurCount)
@@ -327,7 +324,8 @@ private[internal] trait TypeMaps {
327
324
}
328
325
}
329
326
def extrapolate (tpe : Type ): Type = {
330
- tparams foreach (t => occurCount(t) = 0 )
327
+ for (tparam <- tparams)
328
+ occurCount(tparam) = 0
331
329
countOccs(tpe)
332
330
for (tparam <- tparams)
333
331
countOccs(tparam.info)
@@ -336,12 +334,12 @@ private[internal] trait TypeMaps {
336
334
}
337
335
338
336
/** If these conditions all hold:
339
- * 1) we are in covariant (or contravariant) position
340
- * 2) this type occurs exactly once in the existential scope
341
- * 3) the widened upper (or lower) bound of this type contains no references to tparams
342
- * Then we replace this lone occurrence of the type with the widened upper (or lower) bound.
343
- * All other types pass through unchanged.
344
- */
337
+ * 1) we are in covariant (or contravariant) position
338
+ * 2) this type occurs exactly once in the existential scope
339
+ * 3) the widened upper (or lower) bound of this type contains no references to tparams
340
+ * Then we replace this lone occurrence of the type with the widened upper (or lower) bound.
341
+ * All other types pass through unchanged.
342
+ */
345
343
def apply (tp : Type ): Type = {
346
344
val tp1 = mapOver(tp)
347
345
if (variance.isInvariant) tp1
@@ -352,7 +350,7 @@ private[internal] trait TypeMaps {
352
350
val word = if (variance.isPositive) " upper" else " lower"
353
351
s " Widened lone occurrence of $tp1 inside existential to $word bound "
354
352
}
355
- if (! repl.typeSymbol.isBottomClass && ! anyContains.collect(repl))
353
+ if (! repl.typeSymbol.isBottomClass && ! anyContains.collect(repl))
356
354
debuglogResult(msg)(repl)
357
355
else
358
356
tp1
@@ -918,7 +916,7 @@ private[internal] trait TypeMaps {
918
916
}
919
917
920
918
/** Note: This map is needed even for non-dependent method types, despite what the name might imply.
921
- */
919
+ */
922
920
class InstantiateDependentMap (params : List [Symbol ], actuals0 : List [Type ]) extends TypeMap with KeepOnlyTypeConstraints {
923
921
private [this ] var _actuals : Array [Type ] = _
924
922
private [this ] var _existentials : Array [Symbol ] = _
@@ -946,37 +944,38 @@ private[internal] trait TypeMaps {
946
944
947
945
private object StableArgTp {
948
946
// type of actual arg corresponding to param -- if the type is stable
949
- def unapply (param : Symbol ): Option [Type ] = ( params indexOf param) match {
947
+ def unapply (param : Symbol ): Option [Type ] = params. indexOf( param) match {
950
948
case - 1 => None
951
949
case pid =>
952
950
val tp = actuals(pid)
953
- if (tp.isStable && ( tp.typeSymbol != NothingClass ) ) Some (tp)
951
+ if (tp.isStable && tp.typeSymbol != NothingClass ) Some (tp)
954
952
else None
955
953
}
956
954
}
957
955
958
956
/** Return the type symbol for referencing a parameter that's instantiated to an unstable actual argument.
959
957
*
960
- * To soundly abstract over an unstable value (x: T) while retaining the most type information,
961
- * use `x.type forSome { type x.type <: T with Singleton}`
962
- * `typeOf[T].narrowExistentially(symbolOf[x])`.
958
+ * To soundly abstract over an unstable value (x: T) while retaining the most type information,
959
+ * use `x.type forSome { type x.type <: T with Singleton}`
960
+ * `typeOf[T].narrowExistentially(symbolOf[x])`.
963
961
*
964
- * See also: captureThis in AsSeenFromMap.
962
+ * See also: captureThis in AsSeenFromMap.
965
963
*/
966
- private def existentialFor (pid : Int ) = {
967
- if (existentials(pid) eq null ) {
968
- val param = params(pid)
969
- existentials(pid) = (
970
- param.owner.newExistential(param.name.toTypeName append nme.SINGLETON_SUFFIX , param.pos, param.flags)
971
- setInfo singletonBounds(actuals(pid))
972
- )
964
+ private def existentialFor (pid : Int ) =
965
+ existentials(pid) match {
966
+ case null =>
967
+ val param = params(pid)
968
+ val exst =
969
+ param.owner.newExistential(param.name.toTypeName.append(nme.SINGLETON_SUFFIX ), param.pos, param.flags)
970
+ .setInfo(singletonBounds(actuals(pid)))
971
+ existentials(pid) = exst
972
+ exst
973
+ case exst => exst
973
974
}
974
- existentials(pid)
975
- }
976
975
977
976
private object UnstableArgTp {
978
977
// existential quantifier and type of corresponding actual arg with unstable type
979
- def unapply (param : Symbol ): Option [(Symbol , Type )] = ( params indexOf param) match {
978
+ def unapply (param : Symbol ): Option [(Symbol , Type )] = params. indexOf( param) match {
980
979
case - 1 => None
981
980
case pid =>
982
981
val sym = existentialFor(pid)
0 commit comments