@@ -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,7 +693,7 @@ 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 ) =
@@ -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
@@ -827,7 +827,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
827
827
case rt => MethodType (Nil , Nil , rt)
828
828
case tp1 => this (tp1).nn
829
829
830
- private def eraseDerivedValueClass (tp : Type )(using Context ): Type | Null = {
830
+ private def eraseDerivedValueClass (tp : Type )(using Context ): Type = {
831
831
val cls = tp.classSymbol.asClass
832
832
val unbox = valueClassUnbox(cls)
833
833
if unbox.exists then
@@ -837,7 +837,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
837
837
// The underlying part of an ErasedValueType cannot be an ErasedValueType itself
838
838
val erase = erasureFn(sourceLanguage, semiEraseVCs = false , isConstructor, isSymbol, inSigName)
839
839
val erasedUnderlying = erase(underlying)
840
- if erasedUnderlying == null then return null
840
+ if erasedUnderlying. isInstanceOf [ WildcardType ] then return WildcardType
841
841
842
842
// Ideally, we would just use `erasedUnderlying` as the erasure of `tp`, but to
843
843
// be binary-compatible with Scala 2 we need two special cases for polymorphic
@@ -891,15 +891,14 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
891
891
892
892
/** The name of the type as it is used in `Signature`s.
893
893
*
894
- * If `tp` is null , or if computing its erasure requires erasing a
894
+ * If `tp` is WildcardType , or if computing its erasure requires erasing a
895
895
* WildcardType or an uninstantiated type variable, then the special name
896
896
* `tpnme.Uninstantiated` which is used to signal an underdefined signature
897
897
* is used.
898
898
*
899
899
* Note: Need to ensure correspondence with erasure!
900
900
*/
901
- private def sigName (tp : Type | Null )(using Context ): TypeName = try
902
- if tp == null then return tpnme.Uninstantiated
901
+ private def sigName (tp : Type )(using Context ): TypeName = try
903
902
tp match {
904
903
case tp : TypeRef =>
905
904
if (! tp.denot.exists)
@@ -913,7 +912,6 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
913
912
}
914
913
if (semiEraseVCs && isDerivedValueClass(sym)) {
915
914
val erasedVCRef = eraseDerivedValueClass(tp)
916
- if erasedVCRef == null then return tpnme.Uninstantiated
917
915
if (erasedVCRef.exists) return sigName(erasedVCRef)
918
916
}
919
917
if (defn.isSyntheticFunctionClass(sym))
@@ -960,7 +958,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
960
958
tpnme.Uninstantiated
961
959
case tp : ErrorType =>
962
960
tpnme.ERROR
963
- case _ if tp eq NoType => // Can't write `case NoType` because of #18083.
961
+ case NoType =>
964
962
tpnme.ERROR
965
963
case _ =>
966
964
val erasedTp = this (tp)
0 commit comments