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 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 } }