@@ -209,19 +209,19 @@ object TypeErasure {
209
209
* @param tp The type to erase.
210
210
*/
211
211
def erasure (tp : Type )(using Context ): Type =
212
- erasureFn(sourceLanguage = SourceLanguage .Scala3 , semiEraseVCs = false , isConstructor = false , isSymbol = false , inSigName = false )(tp)(using preErasureCtx).nn
212
+ erasureFn(sourceLanguage = SourceLanguage .Scala3 , semiEraseVCs = false , isConstructor = false , isSymbol = false , inSigName = false )(tp)(using preErasureCtx)
213
213
214
214
/** The value class erasure of a Scala type, where value classes are semi-erased to
215
215
* ErasedValueType (they will be fully erased in [[ElimErasedValueType ]]).
216
216
*
217
217
* @param tp The type to erase.
218
218
*/
219
219
def valueErasure (tp : Type )(using Context ): Type =
220
- erasureFn(sourceLanguage = SourceLanguage .Scala3 , semiEraseVCs = true , isConstructor = false , isSymbol = false , inSigName = false )(tp)(using preErasureCtx).nn
220
+ erasureFn(sourceLanguage = SourceLanguage .Scala3 , semiEraseVCs = true , isConstructor = false , isSymbol = false , inSigName = false )(tp)(using preErasureCtx)
221
221
222
222
/** The erasure that Scala 2 would use for this type. */
223
223
def scala2Erasure (tp : Type )(using Context ): Type =
224
- erasureFn(sourceLanguage = SourceLanguage .Scala2 , semiEraseVCs = true , isConstructor = false , isSymbol = false , inSigName = false )(tp)(using preErasureCtx).nn
224
+ erasureFn(sourceLanguage = SourceLanguage .Scala2 , semiEraseVCs = true , isConstructor = false , isSymbol = false , inSigName = false )(tp)(using preErasureCtx)
225
225
226
226
/** Like value class erasure, but value classes erase to their underlying type erasure */
227
227
def fullErasure (tp : Type )(using Context ): Type =
@@ -270,8 +270,8 @@ object TypeErasure {
270
270
if (defn.isPolymorphicAfterErasure(sym)) eraseParamBounds(sym.info.asInstanceOf [PolyType ])
271
271
else if (sym.isAbstractType) TypeAlias (WildcardType )
272
272
else if sym.is(ConstructorProxy ) then NoType
273
- else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(using preErasureCtx).nn )
274
- else if (sym.is(Label )) erase.eraseResult(sym.info)(using preErasureCtx).nn
273
+ else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(using preErasureCtx))
274
+ else if (sym.is(Label )) erase.eraseResult(sym.info)(using preErasureCtx)
275
275
else erase.eraseInfo(tp, sym)(using preErasureCtx) match {
276
276
case einfo : MethodType =>
277
277
if (sym.isGetter && einfo.resultType.isRef(defn.UnitClass ))
@@ -596,10 +596,10 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
596
596
*
597
597
* If computing the erasure of T requires erasing a WildcardType or an
598
598
* uninstantiated type variable, then an exception signaling an internal
599
- * error will be thrown, unless `inSigName` is set in which case `null`
599
+ * error will be thrown, unless `inSigName` is set in which case WildcardType
600
600
* will be returned.
601
601
*
602
- * In all other situations, |T| will be non-null and computed as follow:
602
+ * In all other situations, |T| will be computed as follow:
603
603
* - For a refined type scala.Array+[T]:
604
604
* - if T is Nothing or Null, []Object
605
605
* - otherwise, if T <: Object, []|T|
@@ -631,7 +631,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
631
631
* - For NoType or NoPrefix, the type itself.
632
632
* - For any other type, exception.
633
633
*/
634
- private def apply (tp : Type )(using Context ): Type | Null =
634
+ private def apply (tp : Type )(using Context ): Type =
635
635
val etp = tp match
636
636
case _ : ErasedValueType =>
637
637
tp
@@ -655,7 +655,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
655
655
case SuperType (thistpe, supertpe) =>
656
656
val eThis = this (thistpe)
657
657
val eSuper = this (supertpe)
658
- if eThis == null || eSuper == null then null
658
+ if eThis. isInstanceOf [ WildcardType ] || eSuper. isInstanceOf [ WildcardType ] then WildcardType
659
659
else SuperType (eThis, eSuper)
660
660
case ExprType (rt) =>
661
661
defn.FunctionType (0 )
@@ -665,7 +665,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
665
665
eraseErasedFunctionApply(refinedInfo)
666
666
case tp : TypeVar if ! tp.isInstantiated =>
667
667
assert(inSigName, i " Cannot erase uninstantiated type variable $tp" )
668
- null
668
+ WildcardType
669
669
case tp : TypeProxy =>
670
670
this (tp.underlying)
671
671
case tp @ AndType (tp1, tp2) =>
@@ -676,7 +676,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
676
676
else
677
677
val e1 = this (tp1)
678
678
val e2 = this (tp2)
679
- if e1 == null || e2 == null then null
679
+ if e1. isInstanceOf [ WildcardType ] || e2. isInstanceOf [ WildcardType ] then WildcardType
680
680
else erasedGlb(e1, e2)
681
681
case OrType (tp1, tp2) =>
682
682
if isSymbol && sourceLanguage.isScala2 && ctx.settings.scalajs.value then
@@ -693,11 +693,11 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
693
693
else
694
694
val e1 = this (tp1)
695
695
val e2 = this (tp2)
696
- if e1 == null || e2 == null then null
696
+ if e1. isInstanceOf [ WildcardType ] || e2. isInstanceOf [ WildcardType ] then WildcardType
697
697
else TypeComparer .orType(e1, e2, isErased = true )
698
698
case tp : MethodType =>
699
699
def paramErasure (tpToErase : Type ) =
700
- erasureFn(sourceLanguage, semiEraseVCs, isConstructor, isSymbol, inSigName = false )(tpToErase).nn
700
+ erasureFn(sourceLanguage, semiEraseVCs, isConstructor, isSymbol, inSigName = false )(tpToErase)
701
701
val (names, formals0) = if tp.hasErasedParams then
702
702
tp.paramNames
703
703
.zip(tp.paramInfos)
@@ -724,7 +724,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
724
724
else {
725
725
def eraseParent (tp : Type ) = tp.dealias match { // note: can't be opaque, since it's a class parent
726
726
case tp : AppliedType if tp.tycon.isRef(defn.PairClass ) => defn.ObjectType
727
- case _ => apply(tp).nn
727
+ case _ => apply(tp)
728
728
}
729
729
val erasedParents : List [Type ] =
730
730
if ((cls eq defn.ObjectClass ) || cls.isPrimitiveValueClass) Nil
@@ -751,10 +751,10 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
751
751
tp
752
752
case tp : WildcardType =>
753
753
assert(inSigName, i " Cannot erase wildcard type $tp" )
754
- null
754
+ WildcardType
755
755
case tp if (tp `eq` NoType ) || (tp `eq` NoPrefix ) =>
756
756
tp
757
- assert(etp != null || inSigName, i " Unexpected null erasure for $tp" )
757
+ assert(! etp. isInstanceOf [ WildcardType ] || inSigName, i " Unexpected WildcardType erasure for $tp" )
758
758
etp
759
759
760
760
/** Like translucentSuperType, but issue a fatal error if it does not exist. */
@@ -788,15 +788,15 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
788
788
else
789
789
try
790
790
val eElem = erasureFn(sourceLanguage, semiEraseVCs = false , isConstructor, isSymbol, inSigName)(elemtp)
791
- if eElem == null then null
791
+ if eElem. isInstanceOf [ WildcardType ] then WildcardType
792
792
else JavaArrayType (eElem)
793
793
catch case ex : Throwable =>
794
794
handleRecursive(" erase array type" , tp.show, ex)
795
795
}
796
796
797
- private def erasePair (tp : Type )(using Context ): Type | Null = {
797
+ private def erasePair (tp : Type )(using Context ): Type = {
798
798
val arity = tupleArity(tp)
799
- if arity == - 2 then null // erasure depends on an uninstantiated type variable or WildcardType
799
+ if arity == - 2 then WildcardType // erasure depends on an uninstantiated type variable or WildcardType
800
800
else if arity == - 1 then defn.ProductClass .typeRef
801
801
else if arity <= Definitions .MaxTupleArity then defn.TupleType (arity).nn
802
802
else defn.TupleXXLClass .typeRef
@@ -807,13 +807,12 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
807
807
* to the underlying type.
808
808
*/
809
809
def eraseInfo (tp : Type , sym : Symbol )(using Context ): Type =
810
- assert(! inSigName) // therefore apply(...).nn won't fail
811
810
val tp1 = tp match
812
811
case tp : MethodicType => integrateContextResults(tp, contextResultCount(sym))
813
812
case _ => tp
814
813
tp1 match
815
814
case ExprType (rt) =>
816
- if sym.is(Param ) then apply(tp1).nn
815
+ if sym.is(Param ) then apply(tp1)
817
816
// Note that params with ExprTypes are eliminated by ElimByName,
818
817
// but potentially re-introduced by ResolveSuper, when we add
819
818
// forwarders to mixin methods.
@@ -825,9 +824,9 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
825
824
eraseResult(tp1.resultType) match
826
825
case rt : MethodType => rt
827
826
case rt => MethodType (Nil , Nil , rt)
828
- case tp1 => this (tp1).nn
827
+ case tp1 => this (tp1)
829
828
830
- private def eraseDerivedValueClass (tp : Type )(using Context ): Type | Null = {
829
+ private def eraseDerivedValueClass (tp : Type )(using Context ): Type = {
831
830
val cls = tp.classSymbol.asClass
832
831
val unbox = valueClassUnbox(cls)
833
832
if unbox.exists then
@@ -837,7 +836,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
837
836
// The underlying part of an ErasedValueType cannot be an ErasedValueType itself
838
837
val erase = erasureFn(sourceLanguage, semiEraseVCs = false , isConstructor, isSymbol, inSigName)
839
838
val erasedUnderlying = erase(underlying)
840
- if erasedUnderlying == null then return null
839
+ if erasedUnderlying. isInstanceOf [ WildcardType ] then return WildcardType
841
840
842
841
// Ideally, we would just use `erasedUnderlying` as the erasure of `tp`, but to
843
842
// be binary-compatible with Scala 2 we need two special cases for polymorphic
@@ -871,7 +870,6 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
871
870
872
871
/** The erasure of a function result type. */
873
872
def eraseResult (tp : Type )(using Context ): Type =
874
- assert(! inSigName) // therefore apply(...).nn won't fail
875
873
// For a value class V, "new V(x)" should have type V for type adaptation to work
876
874
// correctly (see SIP-15 and [[Erasure.Boxing.adaptToType]]), so the result type of a
877
875
// constructor method should not be semi-erased.
@@ -881,25 +879,24 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
881
879
case tp : TypeRef =>
882
880
val sym = tp.symbol
883
881
if (sym eq defn.UnitClass ) sym.typeRef
884
- else apply(tp).nn
882
+ else apply(tp)
885
883
case tp : AppliedType =>
886
884
val sym = tp.tycon.typeSymbol
887
885
if (sym.isClass && ! erasureDependsOnArgs(sym)) eraseResult(tp.tycon)
888
- else apply(tp).nn
886
+ else apply(tp)
889
887
case _ =>
890
- apply(tp).nn
888
+ apply(tp)
891
889
892
890
/** The name of the type as it is used in `Signature`s.
893
891
*
894
- * If `tp` is null , or if computing its erasure requires erasing a
892
+ * If `tp` is WildcardType , or if computing its erasure requires erasing a
895
893
* WildcardType or an uninstantiated type variable, then the special name
896
894
* `tpnme.Uninstantiated` which is used to signal an underdefined signature
897
895
* is used.
898
896
*
899
897
* Note: Need to ensure correspondence with erasure!
900
898
*/
901
- private def sigName (tp : Type | Null )(using Context ): TypeName = try
902
- if tp == null then return tpnme.Uninstantiated
899
+ private def sigName (tp : Type )(using Context ): TypeName = try
903
900
tp match {
904
901
case tp : TypeRef =>
905
902
if (! tp.denot.exists)
@@ -913,7 +910,6 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
913
910
}
914
911
if (semiEraseVCs && isDerivedValueClass(sym)) {
915
912
val erasedVCRef = eraseDerivedValueClass(tp)
916
- if erasedVCRef == null then return tpnme.Uninstantiated
917
913
if (erasedVCRef.exists) return sigName(erasedVCRef)
918
914
}
919
915
if (defn.isSyntheticFunctionClass(sym))
@@ -958,9 +954,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
958
954
sigName(tp.underlying)
959
955
case tp : WildcardType =>
960
956
tpnme.Uninstantiated
961
- case tp : ErrorType =>
962
- tpnme.ERROR
963
- case _ if tp eq NoType => // Can't write `case NoType` because of #18083.
957
+ case _ : ErrorType | NoType =>
964
958
tpnme.ERROR
965
959
case _ =>
966
960
val erasedTp = this (tp)
0 commit comments