Skip to content

Commit 68a3fa3

Browse files
committed
Use Label field for sum and product mirrors
1 parent 39dbc76 commit 68a3fa3

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
@@ -821,23 +821,23 @@ trait Implicits { self: Typer =>
821821
case monoAlias @ TypeAlias(monoType) =>
822822
if (monoType.termSymbol.is(CaseVal)) {
823823
val modul = monoType.termSymbol
824-
val caseLabel = ConstantType(Constant(modul.name.toString))
824+
val label = ConstantType(Constant(modul.name.toString))
825825
val mirrorType = defn.Mirror_SingletonType
826826
.refinedWith(tpnme.MonoType, monoAlias)
827-
.refinedWith(tpnme.CaseLabel, TypeAlias(caseLabel))
827+
.refinedWith(tpnme.Label, TypeAlias(label))
828828
ref(modul).withSpan(span).cast(mirrorType)
829829
}
830830
else if (monoType.classSymbol.isGenericProduct) {
831831
val cls = monoType.classSymbol
832832
val accessors = cls.caseAccessors.filterNot(_.is(PrivateLocal))
833833
val elemTypes = accessors.map(monoType.memberInfo(_))
834-
val caseLabel = ConstantType(Constant(cls.name.toString))
834+
val label = ConstantType(Constant(cls.name.toString))
835835
val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString)))
836836
val mirrorType =
837837
defn.Mirror_ProductType
838838
.refinedWith(tpnme.MonoType, monoAlias)
839839
.refinedWith(tpnme.ElemTypes, TypeAlias(TypeOps.nestedPairs(elemTypes)))
840-
.refinedWith(tpnme.CaseLabel, TypeAlias(caseLabel))
840+
.refinedWith(tpnme.Label, TypeAlias(label))
841841
.refinedWith(tpnme.ElemLabels, TypeAlias(TypeOps.nestedPairs(elemLabels)))
842842
val modul = cls.linkedClass.sourceModule
843843
assert(modul.is(Module))
@@ -853,6 +853,7 @@ trait Implicits { self: Typer =>
853853
formal.member(tpnme.MonoType).info match {
854854
case monoAlias @ TypeAlias(monoType) if monoType.classSymbol.isGenericSum =>
855855
val cls = monoType.classSymbol
856+
val label = ConstantType(Constant(cls.name.toString))
856857
val elemTypes = cls.children.map {
857858
case caseClass: ClassSymbol =>
858859
assert(caseClass.is(Case))
@@ -880,6 +881,7 @@ trait Implicits { self: Typer =>
880881
val mirrorType =
881882
defn.Mirror_SumType
882883
.refinedWith(tpnme.MonoType, monoAlias)
884+
.refinedWith(tpnme.Label, TypeAlias(label))
883885
.refinedWith(tpnme.ElemTypes, TypeAlias(TypeOps.nestedPairs(elemTypes)))
884886
var modul = cls.linkedClass.sourceModule
885887
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)