Skip to content

Commit

Permalink
Merge pull request #15182 from dotty-staging/mirrors-test-backcompat
Browse files Browse the repository at this point in the history
test backwards compat of mirror changes
  • Loading branch information
bishabosha authored May 13, 2022
2 parents fd6b48f + 2a183f8 commit be65db4
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
59 changes: 59 additions & 0 deletions sbt-test/scala3-compat/anon-prod-mirrors-3.1/app/Main.scala
Original file line number Diff line number Diff line change
@@ -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()
}
7 changes: 7 additions & 0 deletions sbt-test/scala3-compat/anon-prod-mirrors-3.1/build.sbt
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions sbt-test/scala3-compat/anon-prod-mirrors-3.1/lib/Foo.scala
Original file line number Diff line number Diff line change
@@ -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]]
}
}
Original file line number Diff line number Diff line change
@@ -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")
)
}
1 change: 1 addition & 0 deletions sbt-test/scala3-compat/anon-prod-mirrors-3.1/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> app/run

0 comments on commit be65db4

Please sign in to comment.