-
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.
Only override defaultArgument in mirrors of new case classes
And test backwards compat
- Loading branch information
1 parent
3e1f445
commit 15c5e58
Showing
11 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
58 changes: 58 additions & 0 deletions
58
sbt-test/scala3-compat/defaultArgument-mirrors-3.3/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,58 @@ | ||
import scala.deriving.Mirror | ||
|
||
package lib { | ||
|
||
case class NewFoo(x: Int = 1, y: Int) | ||
|
||
object NewMirrors { | ||
val mNewFoo = summon[Mirror.Of[NewFoo]] | ||
|
||
val mOldFoo = summon[Mirror.Of[OldFoo]] | ||
val mOldBar = summon[Mirror.Of[OldBar]] | ||
} | ||
} | ||
|
||
package app { | ||
import lib.* | ||
|
||
object Main { | ||
|
||
// defaultArgument implementation did not throw NoSuchElementException | ||
def foundDefaultArgument(m: Mirror.Product): Boolean = try { | ||
m.defaultArgument(0) | ||
true | ||
} catch { | ||
case _: NoSuchElementException => false | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
|
||
// NewFoo: normal case with support for default arguments | ||
|
||
assert(NewMirrors.mNewFoo.defaultArgument(0) == 1) | ||
summon[NewMirrors.mNewFoo.MirroredElemHasDefaults =:= (true, false)] | ||
|
||
// OldFoo: does not override the defaultArgument implementation | ||
|
||
assert(!foundDefaultArgument(NewMirrors.mOldFoo)) // Expected: since mirror of old case class | ||
summon[NewMirrors.mOldFoo.MirroredElemHasDefaults =:= (false, false)] // Necessary: to be consistent with defaultArgument implementation | ||
|
||
assert(!foundDefaultArgument(OldMirrors.mOldFoo)) // Expected: since mirror of old case class | ||
summon[scala.util.NotGiven[OldMirrors.mOldFoo.MirroredElemHasDefaults <:< (Boolean, Boolean)]] // reference to old mirror doesn't have any refinement | ||
summon[OldMirrors.mOldFoo.MirroredElemHasDefaults <:< Tuple] // but does inherit type member from Mirror trait | ||
|
||
// OldBar: is anon mirror so could implement defaultArgument | ||
// but we manually keep behaviour consistent with other mirrors of old case classes | ||
|
||
assert(NewMirrors.mOldBar ne lib.OldBar) | ||
assert(!foundDefaultArgument(NewMirrors.mOldBar)) | ||
summon[NewMirrors.mOldBar.MirroredElemHasDefaults =:= (false, false)] // Ok: should be consistent with above | ||
|
||
assert(OldMirrors.mOldBar ne lib.OldBar) | ||
assert(!foundDefaultArgument(OldMirrors.mOldBar)) | ||
summon[scala.util.NotGiven[OldMirrors.mOldBar.MirroredElemHasDefaults <:< (Boolean, Boolean)]] | ||
summon[OldMirrors.mOldBar.MirroredElemHasDefaults <:< Tuple] | ||
|
||
} | ||
} | ||
} |
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.3.0" | ||
) | ||
|
||
lazy val app = project.in(file("app")) | ||
.dependsOn(lib) |
13 changes: 13 additions & 0 deletions
13
sbt-test/scala3-compat/defaultArgument-mirrors-3.3/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,13 @@ | ||
package lib | ||
|
||
import deriving.Mirror | ||
|
||
case class OldFoo(x: Int = 1, y: Int) | ||
|
||
case class OldBar(x: Int = 1, y: Int) | ||
case object OldBar | ||
|
||
object OldMirrors { | ||
val mOldFoo = summon[Mirror.ProductOf[OldFoo]] | ||
val mOldBar = summon[Mirror.ProductOf[OldBar]] | ||
} |
11 changes: 11 additions & 0 deletions
11
sbt-test/scala3-compat/defaultArgument-mirrors-3.3/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 |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
case class MyProduct(x: Int) | ||
case class WillGetDefault(x: Int) | ||
case class WillChangeDefault(x: Int = 1) |
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
2 changes: 2 additions & 0 deletions
2
sbt-test/source-dependencies/mirror-product/changes/MyProduct.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 |
---|---|---|
@@ -1 +1,3 @@ | ||
case class MyProduct(x: Int, y: String) | ||
case class WillGetDefault(x: Int = 1) | ||
case class WillChangeDefault(x: Int = 2) |