Skip to content

Commit e50a032

Browse files
oderskymilessabin
authored andcommitted
Use Label field for sum and product mirrors
1 parent 275a0a9 commit e50a032

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ object StdNames {
326326
val AnnotatedType: N = "AnnotatedType"
327327
val AppliedTypeTree: N = "AppliedTypeTree"
328328
val ArrayAnnotArg: N = "ArrayAnnotArg"
329-
val CaseLabel: N = "CaseLabel"
330329
val CAP: N = "CAP"
331330
val Constant: N = "Constant"
332331
val ConstantType: N = "ConstantType"
@@ -338,6 +337,7 @@ object StdNames {
338337
val floatHash: N = "floatHash"
339338
val Ident: N = "Ident"
340339
val Import: N = "Import"
340+
val Label: N = "Label"
341341
val Literal: N = "Literal"
342342
val LiteralAnnotArg: N = "LiteralAnnotArg"
343343
val longHash: N = "longHash"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
367367
* case _: C_1 => 0
368368
* ...
369369
* case _: C_n => n - 1
370+
* }
370371
*
371372
* Here, the normalized type of a class C is C[_, ...., _] with
372373
* a wildcard for each type parameter. The normalized type of an object

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,23 +865,23 @@ trait Implicits { self: Typer =>
865865
case monoAlias @ TypeAlias(monoType) =>
866866
if (monoType.termSymbol.is(CaseVal)) {
867867
val modul = monoType.termSymbol
868-
val caseLabel = ConstantType(Constant(modul.name.toString))
868+
val label = ConstantType(Constant(modul.name.toString))
869869
val mirrorType = defn.Mirror_SingletonType
870870
.refinedWith(tpnme.MonoType, monoAlias)
871-
.refinedWith(tpnme.CaseLabel, TypeAlias(caseLabel))
871+
.refinedWith(tpnme.Label, TypeAlias(label))
872872
ref(modul).withSpan(span).cast(mirrorType)
873873
}
874874
else if (monoType.classSymbol.isGenericProduct) {
875875
val cls = monoType.classSymbol
876876
val accessors = cls.caseAccessors.filterNot(_.is(PrivateLocal))
877877
val elemTypes = accessors.map(monoType.memberInfo(_))
878-
val caseLabel = ConstantType(Constant(cls.name.toString))
878+
val label = ConstantType(Constant(cls.name.toString))
879879
val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString)))
880880
val mirrorType =
881881
defn.Mirror_ProductType
882882
.refinedWith(tpnme.MonoType, monoAlias)
883883
.refinedWith(tpnme.ElemTypes, TypeAlias(TypeOps.nestedPairs(elemTypes)))
884-
.refinedWith(tpnme.CaseLabel, TypeAlias(caseLabel))
884+
.refinedWith(tpnme.Label, TypeAlias(label))
885885
.refinedWith(tpnme.ElemLabels, TypeAlias(TypeOps.nestedPairs(elemLabels)))
886886
val modul = cls.linkedClass.sourceModule
887887
assert(modul.is(Module))
@@ -897,6 +897,7 @@ trait Implicits { self: Typer =>
897897
formal.member(tpnme.MonoType).info match {
898898
case monoAlias @ TypeAlias(monoType) if monoType.classSymbol.isGenericSum =>
899899
val cls = monoType.classSymbol
900+
val label = ConstantType(Constant(cls.name.toString))
900901
val elemTypes = cls.children.map {
901902
case caseClass: ClassSymbol =>
902903
assert(caseClass.is(Case))
@@ -924,6 +925,7 @@ trait Implicits { self: Typer =>
924925
val mirrorType =
925926
defn.Mirror_SumType
926927
.refinedWith(tpnme.MonoType, monoAlias)
928+
.refinedWith(tpnme.Label, TypeAlias(label))
927929
.refinedWith(tpnme.ElemTypes, TypeAlias(TypeOps.nestedPairs(elemTypes)))
928930
var modul = cls.linkedClass.sourceModule
929931
val mirrorRef =

library/src/scala/deriving.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ object deriving {
88

99
/** The mirrored *-type */
1010
type MonoType
11+
12+
/** The name of the type */
13+
type Label <: String
1114
}
1215

1316
object Mirror {
1417

1518
/** The Mirror for a sum type */
1619
trait Sum extends Mirror { self =>
1720

21+
/** The types of the alternatives */
1822
type ElemTypes <: Tuple
1923

2024
/** The ordinal number of the case class of `x`. For enums, `ordinal(x) == x.ordinal` */
@@ -24,12 +28,9 @@ object deriving {
2428
/** The Mirror for a product type */
2529
trait Product extends Mirror {
2630

27-
/** The types of the elements */
31+
/** The types of the product elements */
2832
type ElemTypes <: Tuple
2933

30-
/** The name of the whole product type */
31-
type CaseLabel <: String
32-
3334
/** The names of the product elements */
3435
type ElemLabels <: Tuple
3536

0 commit comments

Comments
 (0)