Skip to content

Commit 9967cee

Browse files
authored
Merge pull request #15391 from TimWSpence/make-anonymous-mirrors-serializable
Make anonymous mirrors serializable
2 parents 76a0b29 + 6ad5987 commit 9967cee

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
228228
val monoTypeDef = untpd.TypeDef(tpnme.MirroredMonoType, untpd.TypeTree(monoType))
229229
var newImpl = untpd.Template(
230230
constr = untpd.emptyConstructor,
231-
parents = untpd.TypeTree(defn.ObjectType) :: Nil,
231+
parents = untpd.TypeTree(defn.ObjectType) :: untpd.TypeTree(defn.JavaSerializableClass.typeRef) :: Nil,
232232
derived = Nil,
233233
self = EmptyValDef,
234234
body = monoTypeDef :: Nil

tests/run/serialize.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ object Test {
2727
}
2828
}
2929

30+
// No Companion defined - therefore anonmymous mirror is generated
31+
sealed trait NoCompanion
32+
case class Value(value: String) extends NoCompanion
33+
3034
def main(args: Array[String]): Unit = {
3135
val x: PartialFunction[Int, Int] = { case x => x + 1 }
3236
val adder = serializeDeserialize(x)
@@ -41,5 +45,10 @@ object Test {
4145
val bar = new a.Bar
4246
val bar1 = serializeDeserialize(bar)
4347
assert(bar.x eq bar1.x)
48+
49+
val mirror = summon[scala.deriving.Mirror.Of[NoCompanion]]
50+
val mirror1 = serializeDeserialize(mirror)
51+
assert(mirror ne mirror1) // update if we start caching anonymous mirrors
52+
assert(mirror1.ordinal(Value("")) == 0) // check API
4453
}
4554
}

0 commit comments

Comments
 (0)