From 2365308bf54e3f19efe4a0a3c1d3c25e0c310822 Mon Sep 17 00:00:00 2001 From: Tim Spence Date: Tue, 7 Jun 2022 12:03:17 +0100 Subject: [PATCH 1/3] Make anonymous mirrors serializable --- compiler/src/dotty/tools/dotc/typer/Synthesizer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala index 36addf639932..3dbde3a1951c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala @@ -228,7 +228,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context): val monoTypeDef = untpd.TypeDef(tpnme.MirroredMonoType, untpd.TypeTree(monoType)) val newImpl = untpd.Template( constr = untpd.emptyConstructor, - parents = untpd.TypeTree(defn.ObjectType) :: Nil, + parents = untpd.TypeTree(defn.ObjectType) :: untpd.TypeTree(defn.JavaSerializableClass.typeRef) :: Nil, derived = Nil, self = EmptyValDef, body = monoTypeDef :: Nil From e5826ab81b3a3ce0878c8dd72648c6c1bb1aa644 Mon Sep 17 00:00:00 2001 From: Tim Spence Date: Tue, 7 Jun 2022 17:57:22 +0100 Subject: [PATCH 2/3] Test to assert that anonymous mirrors are Serializable --- tests/run/curried-mirror.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/run/curried-mirror.scala b/tests/run/curried-mirror.scala index 84c544c7318b..3adc33e14009 100644 --- a/tests/run/curried-mirror.scala +++ b/tests/run/curried-mirror.scala @@ -190,4 +190,12 @@ object Test extends App { val v2 = v0.ordinal(SumV2.Right("foo")) assert(v2 == 1) } + + sealed trait NoCompanion + case class Value(value: String) extends NoCompanion + + { + val mirror = summon[Mirror.Of[NoCompanion]] + assert(mirror.isInstanceOf[Serializable]) + } } From 6ad5987bb33456a06c72e89be8d61d5db6a01b60 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Wed, 8 Jun 2022 13:06:44 +0200 Subject: [PATCH 3/3] move test --- tests/run/curried-mirror.scala | 8 -------- tests/run/serialize.scala | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/run/curried-mirror.scala b/tests/run/curried-mirror.scala index 3adc33e14009..84c544c7318b 100644 --- a/tests/run/curried-mirror.scala +++ b/tests/run/curried-mirror.scala @@ -190,12 +190,4 @@ object Test extends App { val v2 = v0.ordinal(SumV2.Right("foo")) assert(v2 == 1) } - - sealed trait NoCompanion - case class Value(value: String) extends NoCompanion - - { - val mirror = summon[Mirror.Of[NoCompanion]] - assert(mirror.isInstanceOf[Serializable]) - } } diff --git a/tests/run/serialize.scala b/tests/run/serialize.scala index 830c2935ac97..12e0ab7c2def 100644 --- a/tests/run/serialize.scala +++ b/tests/run/serialize.scala @@ -27,6 +27,10 @@ object Test { } } + // No Companion defined - therefore anonmymous mirror is generated + sealed trait NoCompanion + case class Value(value: String) extends NoCompanion + def main(args: Array[String]): Unit = { val x: PartialFunction[Int, Int] = { case x => x + 1 } val adder = serializeDeserialize(x) @@ -41,5 +45,10 @@ object Test { val bar = new a.Bar val bar1 = serializeDeserialize(bar) assert(bar.x eq bar1.x) + + val mirror = summon[scala.deriving.Mirror.Of[NoCompanion]] + val mirror1 = serializeDeserialize(mirror) + assert(mirror ne mirror1) // update if we start caching anonymous mirrors + assert(mirror1.ordinal(Value("")) == 0) // check API } }