@@ -249,7 +249,7 @@ object Types {
249
249
}
250
250
251
251
/** The elements of an AndType or OrType */
252
- def factors (implicit ctx : Context ): List [Type ] = this match {
252
+ final def factors (implicit ctx : Context ): List [Type ] = this match {
253
253
case tp : AndType =>
254
254
def components (tp : Type ): List [Type ] = tp match {
255
255
case AndType (tp1, tp2) => components(tp1) ++ components(tp2)
@@ -266,7 +266,7 @@ object Types {
266
266
}
267
267
268
268
/** The parameter types of a PolyType or MethodType, Empty list for others */
269
- def paramTypess : List [List [Type ]] = this match {
269
+ final def paramTypess : List [List [Type ]] = this match {
270
270
case mt : MethodType => mt.paramTypes :: mt.resultType.paramTypess
271
271
case pt : PolyType => pt.paramTypess
272
272
case _ => Nil
@@ -281,13 +281,13 @@ object Types {
281
281
}
282
282
283
283
/** Map function over elements of an AndType, rebuilding with & */
284
- def mapAnd (f : Type => Type )(implicit ctx : Context ): Type = this match {
284
+ final def mapAnd (f : Type => Type )(implicit ctx : Context ): Type = this match {
285
285
case AndType (tp1, tp2) => tp1.mapAnd(f) & tp2.mapAnd(f)
286
286
case _ => f(this )
287
287
}
288
288
289
289
/** Map function over elements of an OrType, rebuilding with | */
290
- def mapOr (f : Type => Type )(implicit ctx : Context ): Type = this match {
290
+ final def mapOr (f : Type => Type )(implicit ctx : Context ): Type = this match {
291
291
case OrType (tp1, tp2) => tp1.mapOr(f) | tp2.mapOr(f)
292
292
case _ => f(this )
293
293
}
@@ -402,7 +402,7 @@ object Types {
402
402
* - Or phase.erasedTypes is false and both types are neither method nor
403
403
* poly types.
404
404
*/
405
- def matches (that : Type )(implicit ctx : Context ): Boolean =
405
+ final def matches (that : Type )(implicit ctx : Context ): Boolean =
406
406
ctx.typeComparer.matchesType(this , that, ! ctx.phase.erasedTypes)
407
407
408
408
/** Does this type match that type
@@ -614,41 +614,41 @@ object Types {
614
614
finishHash(hashing.mix(seed, elemHash), arity + 1 , tps)
615
615
}
616
616
617
- protected def doHash (x : Any ): Int =
617
+ protected final def doHash (x : Any ): Int =
618
618
finishHash(hashing.mix(hashSeed, x.hashCode), 1 )
619
619
620
- protected def doHash (tp : Type ): Int =
620
+ protected final def doHash (tp : Type ): Int =
621
621
finishHash(hashSeed, 0 , tp)
622
622
623
- protected def doHash (x1 : Any , tp2 : Type ): Int =
623
+ protected final def doHash (x1 : Any , tp2 : Type ): Int =
624
624
finishHash(hashing.mix(hashSeed, x1.hashCode), 1 , tp2)
625
625
626
- protected def doHash (tp1 : Type , tp2 : Type ): Int =
626
+ protected final def doHash (tp1 : Type , tp2 : Type ): Int =
627
627
finishHash(hashSeed, 0 , tp1, tp2)
628
628
629
- protected def doHash (x1 : Any , tp2 : Type , tp3 : Type ): Int =
629
+ protected final def doHash (x1 : Any , tp2 : Type , tp3 : Type ): Int =
630
630
finishHash(hashing.mix(hashSeed, x1.hashCode), 1 , tp2, tp3)
631
631
632
- protected def doHash (tp1 : Type , tps2 : List [Type ]): Int =
632
+ protected final def doHash (tp1 : Type , tps2 : List [Type ]): Int =
633
633
finishHash(hashSeed, 0 , tp1, tps2)
634
634
635
- protected def doHash (x1 : Any , tp2 : Type , tps3 : List [Type ]): Int =
635
+ protected final def doHash (x1 : Any , tp2 : Type , tps3 : List [Type ]): Int =
636
636
finishHash(hashing.mix(hashSeed, x1.hashCode), 1 , tp2, tps3)
637
637
638
638
} // end Type
639
639
640
640
/** A marker trait for cached types */
641
- trait CachedType extends Type
641
+ sealed trait CachedType extends Type
642
642
643
- def unique [T <: Type ](tp : T )(implicit ctx : Context ): T = {
643
+ final def unique [T <: Type ](tp : T )(implicit ctx : Context ): T = {
644
644
if (tp.hash == NotCached ) tp
645
645
else ctx.uniques.findEntryOrUpdate(tp).asInstanceOf [T ]
646
646
}
647
647
648
648
/** A marker trait for type proxies.
649
649
* Each implementation is expected to redefine the `underlying` method.
650
650
*/
651
- abstract class TypeProxy extends Type {
651
+ sealed abstract class TypeProxy extends Type {
652
652
/** The type to which this proxy forwards operations. */
653
653
def underlying (implicit ctx : Context ): Type
654
654
}
@@ -659,50 +659,50 @@ object Types {
659
659
// is for efficiency.
660
660
661
661
/** Instances of this class are cached and are not proxies. */
662
- abstract class CachedGroundType extends Type with CachedType {
662
+ sealed abstract class CachedGroundType extends Type with CachedType {
663
663
final val hash = computeHash
664
664
override final def hashCode = hash
665
665
def computeHash : Int
666
666
}
667
667
668
668
/** Instances of this class are cached and are proxies. */
669
- abstract class CachedProxyType extends TypeProxy with CachedType {
669
+ sealed abstract class CachedProxyType extends TypeProxy with CachedType {
670
670
final val hash = computeHash
671
671
override final def hashCode = hash
672
672
def computeHash : Int
673
673
}
674
674
675
675
/** Instances of this class are uncached and are not proxies. */
676
- abstract class UncachedGroundType extends Type {
676
+ sealed abstract class UncachedGroundType extends Type {
677
677
final def hash = NotCached
678
678
}
679
679
680
680
/** Instances of this class are uncached and are proxies. */
681
- abstract class UncachedProxyType extends TypeProxy {
681
+ sealed abstract class UncachedProxyType extends TypeProxy {
682
682
final def hash = NotCached
683
683
}
684
684
685
685
/** A marker trait for types that are guaranteed to contain only a
686
686
* single non-null value (they might contain null in addition).
687
687
*/
688
- trait SingletonType extends TypeProxy
688
+ sealed trait SingletonType extends TypeProxy
689
689
690
690
/** A marker trait for types that apply only to type symbols */
691
- trait TypeType extends Type
691
+ sealed trait TypeType extends Type
692
692
693
693
// --- NamedTypes ------------------------------------------------------------------
694
694
695
695
/** A NamedType of the form Prefix # name
696
696
*/
697
- abstract class NamedType extends CachedProxyType {
697
+ sealed abstract class NamedType extends CachedProxyType {
698
698
699
699
val prefix : Type
700
700
val name : Name
701
701
702
702
private [this ] var lastDenotation : Denotation = null
703
703
704
704
/** The denotation currently denoted by this type */
705
- def denot (implicit ctx : Context ): Denotation = {
705
+ final def denot (implicit ctx : Context ): Denotation = {
706
706
val validPeriods =
707
707
if (lastDenotation != null ) lastDenotation.validFor else Nowhere
708
708
if (! (validPeriods contains ctx.period)) {
@@ -728,17 +728,17 @@ object Types {
728
728
729
729
protected def loadDenot (implicit ctx : Context ) = prefix.member(name)
730
730
731
- def isType = name.isTypeName
732
- def isTerm = name.isTermName
731
+ final def isType = name.isTypeName
732
+ final def isTerm = name.isTermName
733
733
734
734
def symbol (implicit ctx : Context ): Symbol = denot.symbol
735
- def info (implicit ctx : Context ): Type = denot.info
735
+ final def info (implicit ctx : Context ): Type = denot.info
736
736
737
737
override def underlying (implicit ctx : Context ): Type = info
738
738
739
- def isAbstractType (implicit ctx : Context ) = info.isRealTypeBounds
739
+ final def isAbstractType (implicit ctx : Context ) = info.isRealTypeBounds
740
740
741
- def derivedNamedType (prefix : Type , name : Name )(implicit ctx : Context ): Type =
741
+ final def derivedNamedType (prefix : Type , name : Name )(implicit ctx : Context ): Type =
742
742
if (prefix eq this .prefix) this
743
743
else NamedType (prefix, name)
744
744
@@ -749,10 +749,10 @@ object Types {
749
749
750
750
sealed abstract case class TypeRef (override val prefix : Type , name : TypeName ) extends NamedType
751
751
752
- trait HasFixedSym extends NamedType {
752
+ sealed trait HasFixedSym extends NamedType {
753
753
protected val fixedSym : Symbol
754
- override def symbol (implicit ctx : Context ): Symbol = fixedSym
755
- override def loadDenot (implicit ctx : Context ) = {
754
+ override final def symbol (implicit ctx : Context ): Symbol = fixedSym
755
+ override final def loadDenot (implicit ctx : Context ) = {
756
756
val denot = fixedSym.denot
757
757
val owner = denot.owner
758
758
if (owner.isTerm) denot else denot.asSeenFrom(prefix, owner).toDenot
@@ -859,7 +859,7 @@ object Types {
859
859
override def computeHash = doHash(name, info, parent)
860
860
}
861
861
862
- class CachedRefinedType (parent : Type , name : Name , infof : RefinedType => Type ) extends RefinedType (parent, name)(infof)
862
+ final class CachedRefinedType (parent : Type , name : Name , infof : RefinedType => Type ) extends RefinedType (parent, name)(infof)
863
863
864
864
object RefinedType {
865
865
def make (parent : Type , names : List [Name ], infofs : List [RefinedType => Type ])(implicit ctx : Context ): Type =
@@ -879,7 +879,7 @@ object Types {
879
879
880
880
type This <: AndType
881
881
882
- def derivedAndType (t1 : Type , t2 : Type )(implicit ctx : Context ) =
882
+ final def derivedAndType (t1 : Type , t2 : Type )(implicit ctx : Context ) =
883
883
if ((t1 eq tp1) && (t2 eq tp2)) this
884
884
else AndType (t1, t2)
885
885
@@ -894,11 +894,11 @@ object Types {
894
894
}
895
895
896
896
sealed abstract case class OrType (tp1 : Type , tp2 : Type ) extends CachedGroundType {
897
- def derivedOrType (t1 : Type , t2 : Type )(implicit ctx : Context ) =
897
+ final def derivedOrType (t1 : Type , t2 : Type )(implicit ctx : Context ) =
898
898
if ((t1 eq tp1) && (t2 eq tp2)) this
899
899
else OrType (t1, t2)
900
900
901
- override def computeHash = doHash(tp1, tp2)
901
+ override final def computeHash = doHash(tp1, tp2)
902
902
}
903
903
904
904
final class CachedOrType (tp1 : Type , tp2 : Type ) extends OrType (tp1, tp2)
@@ -910,14 +910,14 @@ object Types {
910
910
911
911
// ----- Method types: MethodType/ExprType/PolyType/MethodParam/PolyParam ---------------
912
912
913
- trait BindingType extends Type
913
+ sealed trait BindingType extends Type
914
914
915
915
// Note: method types are cached whereas poly types are not.
916
916
// The reason is that most poly types are cyclic via poly params,
917
917
// and therefore two different poly types would never be equal.
918
918
919
919
sealed abstract case class MethodType (paramNames : List [TermName ], paramTypes : List [Type ])(resultTypeExp : MethodType => Type ) extends CachedGroundType with BindingType {
920
- override lazy val resultType = resultTypeExp(this )
920
+ override final lazy val resultType = resultTypeExp(this )
921
921
def isJava = false
922
922
def isImplicit = false
923
923
@@ -926,7 +926,7 @@ object Types {
926
926
case _ => false
927
927
}
928
928
929
- override lazy val signature : List [TypeName ] = {
929
+ override final lazy val signature : List [TypeName ] = {
930
930
def paramSig (tp : Type ): TypeName = ???
931
931
val followSig = resultType match {
932
932
case rtp : MethodType => rtp.signature
@@ -935,7 +935,7 @@ object Types {
935
935
(paramTypes map paramSig) ++ followSig
936
936
}
937
937
938
- def derivedMethodType (paramNames : List [TermName ], paramTypes : List [Type ], restpe : Type )(implicit ctx : Context ) =
938
+ final def derivedMethodType (paramNames : List [TermName ], paramTypes : List [Type ], restpe : Type )(implicit ctx : Context ) =
939
939
if ((paramNames eq this .paramNames) && (paramTypes eq this .paramTypes) && (restpe eq this .resultType)) this
940
940
else {
941
941
val restpeExpr = (x : MethodType ) => restpe.subst(this , x)
@@ -944,11 +944,11 @@ object Types {
944
944
else MethodType (paramNames, paramTypes)(restpeExpr)
945
945
}
946
946
947
- def instantiate (argTypes : List [Type ])(implicit ctx : Context ): Type =
947
+ final def instantiate (argTypes : List [Type ])(implicit ctx : Context ): Type =
948
948
if (isDependent) new InstMethodMap (this , argTypes) apply resultType
949
949
else resultType
950
950
951
- override def computeHash = doHash(paramNames, resultType, paramTypes)
951
+ override final def computeHash = doHash(paramNames, resultType, paramTypes)
952
952
}
953
953
954
954
final class CachedMethodType (paramNames : List [TermName ], paramTypes : List [Type ])(resultTypeExp : MethodType => Type )
@@ -964,9 +964,9 @@ object Types {
964
964
override def isImplicit = true
965
965
}
966
966
967
- abstract class GenericMethodType {
967
+ sealed abstract class GenericMethodType {
968
968
def apply (paramNames : List [TermName ], paramTypes : List [Type ])(resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType
969
- def fromSymbols (params : List [Symbol ], resultType : Type )(implicit ctx : Context ) = {
969
+ final def fromSymbols (params : List [Symbol ], resultType : Type )(implicit ctx : Context ) = {
970
970
def transResult (mt : MethodType ) =
971
971
resultType.subst(params, (0 until params.length).toList map (MethodParam (mt, _)))
972
972
apply(params map (_.name.asTermName), params map (_.info))(transResult _)
@@ -1042,7 +1042,7 @@ object Types {
1042
1042
}
1043
1043
}
1044
1044
1045
- abstract class BoundType extends UncachedProxyType {
1045
+ sealed abstract class BoundType extends UncachedProxyType {
1046
1046
type BT <: BindingType
1047
1047
def binder : BT
1048
1048
def copy (bt : BT ): Type
@@ -1076,19 +1076,19 @@ object Types {
1076
1076
/* def typeTemplate(implicit ctx: Context): Type =
1077
1077
classd.typeTemplate asSeenFrom (prefix, classd.symbol)
1078
1078
*/
1079
- def typeConstructor (implicit ctx : Context ): Type =
1079
+ final def typeConstructor (implicit ctx : Context ): Type =
1080
1080
NamedType (prefix, classd.symbol.name)
1081
1081
1082
1082
// cached because baseType needs parents
1083
- private var parentsCache : List [TypeRef ] = null
1083
+ private final var parentsCache : List [TypeRef ] = null
1084
1084
1085
- override def parents (implicit ctx : Context ): List [TypeRef ] = {
1085
+ override final def parents (implicit ctx : Context ): List [TypeRef ] = {
1086
1086
if (parentsCache == null )
1087
1087
parentsCache = classd.parents.mapConserve(_.substThis(classd.symbol, prefix).asInstanceOf [TypeRef ])
1088
1088
parentsCache
1089
1089
}
1090
1090
1091
- override def computeHash = doHash(classd.symbol, prefix)
1091
+ override final def computeHash = doHash(classd.symbol, prefix)
1092
1092
}
1093
1093
1094
1094
final class CachedClassInfo (prefix : Type , classd : ClassDenotation ) extends ClassInfo (prefix, classd)
@@ -1099,25 +1099,25 @@ object Types {
1099
1099
}
1100
1100
1101
1101
sealed abstract case class TypeBounds (lo : Type , hi : Type ) extends CachedProxyType with TypeType {
1102
- override def underlying (implicit ctx : Context ): Type = hi
1103
- def derivedTypeBounds (lo1 : Type , hi1 : Type )(implicit ctx : Context ) =
1102
+ override final def underlying (implicit ctx : Context ): Type = hi
1103
+ final def derivedTypeBounds (lo1 : Type , hi1 : Type )(implicit ctx : Context ) =
1104
1104
if ((lo1 eq lo) && (hi1 eq hi)) this
1105
1105
else TypeBounds (lo, hi)
1106
1106
1107
- def contains (tp : Type )(implicit ctx : Context ) = lo <:< tp && tp <:< hi
1107
+ final def contains (tp : Type )(implicit ctx : Context ) = lo <:< tp && tp <:< hi
1108
1108
1109
- def & (that : TypeBounds )(implicit ctx : Context ): TypeBounds =
1109
+ final def & (that : TypeBounds )(implicit ctx : Context ): TypeBounds =
1110
1110
TypeBounds (this .lo | that.lo, this .hi & that.hi)
1111
- def | (that : TypeBounds )(implicit ctx : Context ): TypeBounds =
1111
+ final def | (that : TypeBounds )(implicit ctx : Context ): TypeBounds =
1112
1112
TypeBounds (this .lo & that.lo, this .hi | that.hi)
1113
1113
1114
- def substBounds (from : PolyType , to : PolyType )(implicit ctx : Context ) =
1114
+ final def substBounds (from : PolyType , to : PolyType )(implicit ctx : Context ) =
1115
1115
subst(from, to).asInstanceOf [TypeBounds ]
1116
1116
1117
- def map (f : Type => Type )(implicit ctx : Context ): TypeBounds =
1117
+ final def map (f : Type => Type )(implicit ctx : Context ): TypeBounds =
1118
1118
TypeBounds (f(lo), f(hi))
1119
1119
1120
- override def computeHash = doHash(lo, hi)
1120
+ override final def computeHash = doHash(lo, hi)
1121
1121
}
1122
1122
1123
1123
final class CachedTypeBounds (lo : Type , hi : Type ) extends TypeBounds (lo, hi)
@@ -1155,6 +1155,13 @@ object Types {
1155
1155
1156
1156
final case class ImportType (expr : TypedTree ) extends UncachedGroundType
1157
1157
1158
+ // Unpickler Types -----------------------------------------------------------------
1159
+ final case class TempPolyType (tparams : List [Symbol ], tpe : Type ) extends UncachedGroundType
1160
+
1161
+ /** Temporary type for classinfos, will be decomposed on completion of the class */
1162
+ final case class TempClassInfoType (parentTypes : List [Type ], decls : Scope , clazz : Symbol ) extends UncachedGroundType
1163
+
1164
+
1158
1165
// Special type objects ------------------------------------------------------------
1159
1166
1160
1167
case object NoType extends UncachedGroundType {
@@ -1167,7 +1174,7 @@ object Types {
1167
1174
override def computeHash = hashSeed
1168
1175
}
1169
1176
1170
- abstract class ErrorType extends UncachedGroundType
1177
+ sealed abstract class ErrorType extends UncachedGroundType
1171
1178
1172
1179
object ErrorType extends ErrorType
1173
1180
@@ -1224,14 +1231,14 @@ object Types {
1224
1231
1225
1232
}
1226
1233
1227
- class InstMethodMap (mt : MethodType , argtypes : List [Type ])(implicit ctx : Context ) extends TypeMap {
1234
+ final class InstMethodMap (mt : MethodType , argtypes : List [Type ])(implicit ctx : Context ) extends TypeMap {
1228
1235
def apply (tp : Type ) = tp match {
1229
1236
case MethodParam (`mt`, n) => argtypes(n)
1230
1237
case _ => mapOver(tp)
1231
1238
}
1232
1239
}
1233
1240
1234
- class InstPolyMap (pt : PolyType , argtypes : List [Type ])(implicit ctx : Context ) extends TypeMap {
1241
+ final class InstPolyMap (pt : PolyType , argtypes : List [Type ])(implicit ctx : Context ) extends TypeMap {
1235
1242
def apply (tp : Type ) = tp match {
1236
1243
case PolyParam (`pt`, n) => argtypes(n)
1237
1244
case _ => mapOver(tp)
@@ -1280,7 +1287,7 @@ object Types {
1280
1287
}
1281
1288
}
1282
1289
1283
- class ExistsAccumulator (p : Type => Boolean ) extends TypeAccumulator [Boolean ] {
1290
+ final class ExistsAccumulator (p : Type => Boolean ) extends TypeAccumulator [Boolean ] {
1284
1291
def apply (x : Boolean , tp : Type ) = x || p(tp) || foldOver(x, tp)
1285
1292
}
1286
1293
0 commit comments