-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15182 from dotty-staging/mirrors-test-backcompat
test backwards compat of mirror changes
- Loading branch information
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
sbt-test/scala3-compat/anon-prod-mirrors-3.1/app/Main.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
sbt-test/scala3-compat/anon-prod-mirrors-3.1/lib/Foo.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
sbt-test/scala3-compat/anon-prod-mirrors-3.1/project/DottyInjectedPlugin.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
> app/run |