diff --git a/sbt-test/scala3-compat/anon-prod-mirrors-3.1/app/Main.scala b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/app/Main.scala new file mode 100644 index 000000000000..dfdc0d952cbd --- /dev/null +++ b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/app/Main.scala @@ -0,0 +1,59 @@ +import scala.deriving.Mirror + +package lib { + object NewMirrors { + val mFoo = summon[Mirror.Of[Foo]] // we can access the constructor of Foo here. + val mFooObj = summon[Mirror.Of[Foo.type]] + + object SubBar extends Bar(1) { + val mBar = summon[deriving.Mirror.ProductOf[Bar]] + val mBarObj = summon[deriving.Mirror.ProductOf[Bar.type]] + } + } +} + +package app { + object Main: + + def testFoo(): Unit = { + val oldMirrorFoo: Mirror.ProductOf[lib.Foo] = lib.OldMirrors.mFoo + val oldMirrorFooObj: Mirror.ProductOf[lib.Foo.type] = lib.OldMirrors.mFooObj + + assert(oldMirrorFoo eq oldMirrorFooObj) // - not good as oldMirrorFoo is really the mirror for `Foo.type` + assert(oldMirrorFooObj eq lib.Foo) // - object Foo is its own mirror + + // 3.1 bug: mirror for Foo behaves as mirror for Foo.type + assert(oldMirrorFooObj.fromProduct(EmptyTuple) == lib.Foo) + + val newMirrorFoo: Mirror.ProductOf[lib.Foo] = lib.NewMirrors.mFoo + val newMirrorFooObj: Mirror.ProductOf[lib.Foo.type] = lib.NewMirrors.mFooObj + + assert(oldMirrorFooObj eq newMirrorFooObj) // mirror for Foo.type has not changed. + + assert(newMirrorFoo ne lib.Foo) // anonymous mirror for Foo + assert(newMirrorFoo.fromProduct(Tuple(23)).x == 23) // mirror for Foo behaves as expected + } + + def testBar(): Unit = { + val oldMirrorBar: Mirror.ProductOf[lib.Bar] = lib.OldMirrors.SubBar.mBar + val oldMirrorBarObj: Mirror.ProductOf[lib.Bar.type] = lib.OldMirrors.SubBar.mBarObj + + assert(oldMirrorBar eq oldMirrorBarObj) // - not good as oldMirrorBar is really the mirror for `Bar.type` + assert(oldMirrorBarObj eq lib.Bar) // - object Bar is its own mirror + + // 3.1 bug: mirror for Bar behaves as mirror for Bar.type + assert(oldMirrorBarObj.fromProduct(EmptyTuple) == lib.Bar) + + val newMirrorBar: Mirror.ProductOf[lib.Bar] = lib.NewMirrors.SubBar.mBar + val newMirrorBarObj: Mirror.ProductOf[lib.Bar.type] = lib.NewMirrors.SubBar.mBarObj + + assert(oldMirrorBarObj eq newMirrorBarObj) // mirror for Bar.type has not changed. + + assert(newMirrorBar ne lib.Bar) // anonymous mirror for Bar + assert(newMirrorBar.fromProduct(Tuple(23)).x == 23) // mirror for Bar behaves as expected + } + + def main(args: Array[String]): Unit = + testFoo() + testBar() +} diff --git a/sbt-test/scala3-compat/anon-prod-mirrors-3.1/build.sbt b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/build.sbt new file mode 100644 index 000000000000..2e220893eae4 --- /dev/null +++ b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/build.sbt @@ -0,0 +1,7 @@ +lazy val lib = project.in(file("lib")) + .settings( + scalaVersion := "3.1.1" + ) + +lazy val app = project.in(file("app")) + .dependsOn(lib) diff --git a/sbt-test/scala3-compat/anon-prod-mirrors-3.1/lib/Foo.scala b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/lib/Foo.scala new file mode 100644 index 000000000000..4395ad64ea97 --- /dev/null +++ b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/lib/Foo.scala @@ -0,0 +1,22 @@ +package lib + +case class Foo private[lib] (x: Int) + +// case object Foo is its own mirror, so the mirror for Foo will be anonymous. +case object Foo + + +case class Bar protected[lib] (x: Int) + +// case object Bar is its own mirror, so the mirror for Bar will be anonymous. +case object Bar + +object OldMirrors { + val mFoo = summon[deriving.Mirror.ProductOf[Foo]] + val mFooObj = summon[deriving.Mirror.ProductOf[Foo.type]] + + object SubBar extends Bar(1) { + val mBar = summon[deriving.Mirror.ProductOf[Bar]] + val mBarObj = summon[deriving.Mirror.ProductOf[Bar.type]] + } +} diff --git a/sbt-test/scala3-compat/anon-prod-mirrors-3.1/project/DottyInjectedPlugin.scala b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/project/DottyInjectedPlugin.scala new file mode 100644 index 000000000000..fb946c4b8c61 --- /dev/null +++ b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/project/DottyInjectedPlugin.scala @@ -0,0 +1,11 @@ +import sbt._ +import Keys._ + +object DottyInjectedPlugin extends AutoPlugin { + override def requires = plugins.JvmPlugin + override def trigger = allRequirements + + override val projectSettings = Seq( + scalaVersion := sys.props("plugin.scalaVersion") + ) +} diff --git a/sbt-test/scala3-compat/anon-prod-mirrors-3.1/test b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/test new file mode 100644 index 000000000000..63092ffa4a03 --- /dev/null +++ b/sbt-test/scala3-compat/anon-prod-mirrors-3.1/test @@ -0,0 +1 @@ +> app/run