Skip to content

Commit 9120105

Browse files
oderskymilessabin
authored andcommitted
Add Mirror.Singleton to enum cases after typer
This makes sure that the mirror type does not leak into the signatures of these cases.
1 parent c031b30 commit 9120105

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ object DesugarEnums {
117117
.withFlags(Override)
118118
def creator = New(Template(
119119
constr = emptyConstructor,
120-
parents = enumClassRef :: TypeTree(defn.Mirror_SingletonType) :: Nil,
120+
parents = enumClassRef :: Nil,
121121
derived = Nil,
122122
self = EmptyValDef,
123123
body = List(enumTagDef, toStringDef) ++ registerCall
124124
))
125125
DefDef(nme.DOLLAR_NEW, Nil,
126126
List(List(param(nme.tag, defn.IntType), param(nme.name, defn.StringType))),
127-
TypeTree(), creator)
127+
TypeTree(), creator).withFlags(Private | Synthetic)
128128
}
129129

130130
/** The return type of an enum case apply method and any widening methods in which
@@ -263,9 +263,7 @@ object DesugarEnums {
263263
DefDef(nme.toString_, Nil, Nil, TypeTree(defn.StringType), Literal(Constant(name.toString)))
264264
.withFlags(Override)
265265
val (tagMeth, scaffolding) = enumTagMeth(CaseKind.Object)
266-
val impl1 = cpy.Template(impl)(
267-
parents = impl.parents :+ TypeTree(defn.Mirror_SingletonType),
268-
body = List(tagMeth, toStringMeth) ++ registerCall)
266+
val impl1 = cpy.Template(impl)(body = List(tagMeth, toStringMeth) ++ registerCall)
269267
val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | Final)
270268
flatTree(scaffolding ::: vdef :: Nil).withSpan(span)
271269
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ object Flags {
626626

627627
/** An enum case */
628628
final val EnumCase: FlagConjunction = allOf(Enum, Case)
629+
final val EnumCaseVal: FlagConjunction = allOf(Enum, CaseVal)
629630

630631
/** A term parameter or parameter accessor */
631632
final val TermParamOrAccessor: FlagSet = Param | ParamAccessor

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
423423
else if (linked.is(Sealed))
424424
derive.println(i"$linked is not a sum because ${linked.whyNotGenericSum}")
425425
}
426+
else if (clazz.isAnonymousClass &&
427+
(clazz.owner.is(EnumCaseVal) ||
428+
clazz.owner.name == nme.DOLLAR_NEW && clazz.owner.is(Synthetic)))
429+
addParent(defn.Mirror_SingletonType)
426430
cpy.Template(impl)(parents = newParents, body = newBody)
427431
}
428432

0 commit comments

Comments
 (0)