@@ -13,6 +13,8 @@ import transform.ContextFunctionResults.*
13
13
import unpickleScala2 .Scala2Erasure
14
14
import Decorators .*
15
15
import Definitions .MaxImplementedFunctionArity
16
+ import dotty .tools .dotc .reporting .trace
17
+
16
18
import scala .annotation .tailrec
17
19
18
20
/** The language in which the definition being erased was written. */
@@ -820,7 +822,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
820
822
case tp1 =>
821
823
this (tp1)
822
824
823
- private def eraseDerivedValueClass (tp : Type )(using Context ): Type = {
825
+ private def eraseDerivedValueClass (tp : Type )(using Context ): Type = trace.force( i " eraseDerivedValueClass $tp " ) {
824
826
val cls = tp.classSymbol.asClass
825
827
val unbox = valueClassUnbox(cls)
826
828
if unbox.exists then
@@ -830,30 +832,33 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
830
832
// The underlying part of an ErasedValueType cannot be an ErasedValueType itself
831
833
val erase = erasureFn(sourceLanguage, semiEraseVCs = false , isConstructor, isSymbol, inSigName)
832
834
val erasedUnderlying = erase(underlying)
833
- if erasedUnderlying.isInstanceOf [WildcardType ] then return WildcardType
834
-
835
- // Ideally, we would just use `erasedUnderlying` as the erasure of `tp`, but to
836
- // be binary-compatible with Scala 2 we need two special cases for polymorphic
837
- // value classes:
838
- // - Given `class Foo[A](x: A) extends AnyVal`, `Foo[X]` should erase like
839
- // `X`, except if its a primitive in which case it erases to the boxed
840
- // version of this primitive.
841
- // - Given `class Bar[A](x: Array[A]) extends AnyVal`, `Bar[X]` will be
842
- // erased like `Array[A]` as seen from its definition site, no matter
843
- // the `X` (same if `A` is bounded).
844
- //
845
- // The binary compatibility is checked by sbt-test/scala2-compat/i8001
846
- val erasedValueClass =
847
- if erasedUnderlying.isPrimitiveValueType && ! genericUnderlying.isPrimitiveValueType then
848
- defn.boxedType(erasedUnderlying)
849
- else if genericUnderlying.derivesFrom(defn.ArrayClass ) then
850
- erasure(genericUnderlying)
851
- else erasedUnderlying
852
-
853
- if erasedValueClass.exists then ErasedValueType (cls.typeRef, erasedValueClass)
854
- else
855
- assert(ctx.reporter.errorsReported, i " no erasure for $underlying" )
856
- NoType
835
+ if erasedUnderlying.isInstanceOf [WildcardType ] then WildcardType
836
+ else {
837
+
838
+ // Ideally, we would just use `erasedUnderlying` as the erasure of `tp`, but to
839
+ // be binary-compatible with Scala 2 we need two special cases for polymorphic
840
+ // value classes:
841
+ // - Given `class Foo[A](x: A) extends AnyVal`, `Foo[X]` should erase like
842
+ // `X`, except if its a primitive in which case it erases to the boxed
843
+ // version of this primitive.
844
+ // - Given `class Bar[A](x: Array[A]) extends AnyVal`, `Bar[X]` will be
845
+ // erased like `Array[A]` as seen from its definition site, no matter
846
+ // the `X` (same if `A` is bounded).
847
+ //
848
+ // The binary compatibility is checked by sbt-test/scala2-compat/i8001
849
+ val erasedValueClass = trace.force(i " erasedValueClass of erasedUnderlying $erasedUnderlying and genericUnderlying $genericUnderlying" ) {
850
+ if erasedUnderlying.isPrimitiveValueType && ! genericUnderlying.isPrimitiveValueType then
851
+ defn.boxedType(erasedUnderlying)
852
+ else if genericUnderlying.derivesFrom(defn.ArrayClass ) then
853
+ erasure(genericUnderlying)
854
+ else erasedUnderlying
855
+ }
856
+
857
+ if erasedValueClass.exists then ErasedValueType (cls.typeRef, erasedValueClass)
858
+ else
859
+ assert(ctx.reporter.errorsReported, i " no erasure for $underlying" )
860
+ NoType
861
+ }
857
862
else NoType
858
863
}
859
864
0 commit comments