Skip to content

Commit 781f18f

Browse files
committed
AugmentScala2Traits: Handle traits that erase to a Scala 2 trait
There is only one of those so far: NonEmptyTuple which erases to Product. Without this commit, the mixin forwarders to Product in the *: class in Tuple.scala were only generated if we happened to have seen augmented Product in a previous compilation unit in the same run.
1 parent 38ecc56 commit 781f18f

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ object TypeErasure {
3636
private def erasureDependsOnArgs(sym: Symbol)(implicit ctx: Context) =
3737
sym == defn.ArrayClass || sym == defn.PairClass
3838

39+
def normalizeClass(cls: ClassSymbol)(implicit ctx: Context): ClassSymbol = {
40+
if (cls.owner == defn.ScalaPackageClass) {
41+
if (defn.specialErasure.contains(cls))
42+
return defn.specialErasure(cls)
43+
if (cls == defn.UnitClass)
44+
return defn.BoxedUnitClass
45+
}
46+
cls
47+
}
48+
3949
/** A predicate that tests whether a type is a legal erased type. Only asInstanceOf and
4050
* isInstanceOf may have types that do not satisfy the predicate.
4151
* ErasedValueType is considered an erased type because it is valid after Erasure (it is
@@ -530,16 +540,6 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
530540
this(tp)
531541
}
532542

533-
private def normalizeClass(cls: ClassSymbol)(implicit ctx: Context): ClassSymbol = {
534-
if (cls.owner == defn.ScalaPackageClass) {
535-
if (defn.specialErasure.contains(cls))
536-
return defn.specialErasure(cls)
537-
if (cls == defn.UnitClass)
538-
return defn.BoxedUnitClass
539-
}
540-
cls
541-
}
542-
543543
/** The name of the type as it is used in `Signature`s.
544544
* Need to ensure correspondence with erasure!
545545
*/

compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this
3939

4040
override def transformTemplate(impl: Template)(implicit ctx: Context): Template = {
4141
val cls = impl.symbol.owner.asClass
42-
for (mixin <- cls.mixins if mixin.is(Scala2x) && !mixin.is(Scala2xPartiallyAugmented))
43-
augmentScala2Trait(mixin)
42+
for (mixin <- cls.mixins) {
43+
val erasedMixin = TypeErasure.normalizeClass(mixin)
44+
if (erasedMixin.is(Scala2x) && !erasedMixin.is(Scala2xPartiallyAugmented))
45+
augmentScala2Trait(erasedMixin)
46+
}
4447
impl
4548
}
4649

0 commit comments

Comments
 (0)