-
Notifications
You must be signed in to change notification settings - Fork 1.1k
support intersection types in mirrorCompanionRef #15192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
import scala.deriving.Mirror | ||
|
||
trait Mixin | ||
object Mixin | ||
|
||
trait Parent | ||
object Parent | ||
|
||
sealed trait Fruit extends Parent | ||
object Fruit { | ||
case object Apple extends Fruit | ||
case object Orange extends Fruit | ||
} | ||
|
||
@main def Test = { | ||
summon[Mirror.SumOf[Fruit & Mixin]] // error: not a sum type | ||
} |
This file contains hidden or 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,40 @@ | ||
-- Error: tests/neg/mirror-synthesis-errors-b.scala:21:56 -------------------------------------------------------------- | ||
21 |val testA = summon[Mirror.ProductOf[Cns[Int] & Sm[Int]]] // error: unreleated | ||
| ^ | ||
|No given instance of type deriving.Mirror.ProductOf[Cns[Int] & Sm[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.ProductOf[Cns[Int] & Sm[Int]]: type `Cns[Int] & Sm[Int]` is not a generic product because its subpart `Cns[Int] & Sm[Int]` is an intersection of unrelated definitions class Cns and class Sm. | ||
-- Error: tests/neg/mirror-synthesis-errors-b.scala:22:56 -------------------------------------------------------------- | ||
22 |val testB = summon[Mirror.ProductOf[Sm[Int] & Cns[Int]]] // error: unreleated | ||
| ^ | ||
|No given instance of type deriving.Mirror.ProductOf[Sm[Int] & Cns[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.ProductOf[Sm[Int] & Cns[Int]]: type `Sm[Int] & Cns[Int]` is not a generic product because its subpart `Sm[Int] & Cns[Int]` is an intersection of unrelated definitions class Sm and class Cns. | ||
-- Error: tests/neg/mirror-synthesis-errors-b.scala:23:49 -------------------------------------------------------------- | ||
23 |val testC = summon[Mirror.Of[Cns[Int] & Sm[Int]]] // error: unreleated | ||
| ^ | ||
|No given instance of type deriving.Mirror.Of[Cns[Int] & Sm[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[Cns[Int] & Sm[Int]]: | ||
| * type `Cns[Int] & Sm[Int]` is not a generic product because its subpart `Cns[Int] & Sm[Int]` is an intersection of unrelated definitions class Cns and class Sm. | ||
| * type `Cns[Int] & Sm[Int]` is not a generic sum because its subpart `Cns[Int] & Sm[Int]` is an intersection of unrelated definitions class Cns and class Sm. | ||
-- Error: tests/neg/mirror-synthesis-errors-b.scala:24:49 -------------------------------------------------------------- | ||
24 |val testD = summon[Mirror.Of[Sm[Int] & Cns[Int]]] // error: unreleated | ||
| ^ | ||
|No given instance of type deriving.Mirror.Of[Sm[Int] & Cns[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[Sm[Int] & Cns[Int]]: | ||
| * type `Sm[Int] & Cns[Int]` is not a generic product because its subpart `Sm[Int] & Cns[Int]` is an intersection of unrelated definitions class Sm and class Cns. | ||
| * type `Sm[Int] & Cns[Int]` is not a generic sum because its subpart `Sm[Int] & Cns[Int]` is an intersection of unrelated definitions class Sm and class Cns. | ||
-- Error: tests/neg/mirror-synthesis-errors-b.scala:25:55 -------------------------------------------------------------- | ||
25 |val testE = summon[Mirror.ProductOf[Sm[Int] & Nn.type]] // error: unreleated | ||
| ^ | ||
|No given instance of type deriving.Mirror.ProductOf[Sm[Int] & Nn.type] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.ProductOf[Sm[Int] & Nn.type]: type `Sm[Int] & Nn.type` is not a generic product because its subpart `Sm[Int] & Nn.type` is an intersection of unrelated definitions class Sm and object Nn. | ||
-- Error: tests/neg/mirror-synthesis-errors-b.scala:26:55 -------------------------------------------------------------- | ||
26 |val testF = summon[Mirror.ProductOf[Nn.type & Sm[Int]]] // error: unreleated | ||
| ^ | ||
|No given instance of type deriving.Mirror.ProductOf[Nn.type & Sm[Int]] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.ProductOf[Nn.type & Sm[Int]]: type `Nn.type & Sm[Int]` is not a generic product because its subpart `Nn.type & Sm[Int]` is an intersection of unrelated definitions object Nn and class Sm. | ||
-- Error: tests/neg/mirror-synthesis-errors-b.scala:27:54 -------------------------------------------------------------- | ||
27 |val testG = summon[Mirror.Of[Foo.A.type & Foo.B.type]] // error: unreleated | ||
| ^ | ||
|No given instance of type deriving.Mirror.Of[(Foo.A : Foo) & (Foo.B : Foo)] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[(Foo.A : Foo) & (Foo.B : Foo)]: | ||
| * type `(Foo.A : Foo) & (Foo.B : Foo)` is not a generic product because its subpart `(Foo.A : Foo) & (Foo.B : Foo)` is an intersection of unrelated definitions value A and value B. | ||
| * type `(Foo.A : Foo) & (Foo.B : Foo)` is not a generic sum because its subpart `(Foo.A : Foo) & (Foo.B : Foo)` is an intersection of unrelated definitions value A and value B. | ||
-- Error: tests/neg/mirror-synthesis-errors-b.scala:28:54 -------------------------------------------------------------- | ||
28 |val testH = summon[Mirror.Of[Foo.B.type & Foo.A.type]] // error: unreleated | ||
| ^ | ||
|No given instance of type deriving.Mirror.Of[(Foo.B : Foo) & (Foo.A : Foo)] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[(Foo.B : Foo) & (Foo.A : Foo)]: | ||
| * type `(Foo.B : Foo) & (Foo.A : Foo)` is not a generic product because its subpart `(Foo.B : Foo) & (Foo.A : Foo)` is an intersection of unrelated definitions value B and value A. | ||
| * type `(Foo.B : Foo) & (Foo.A : Foo)` is not a generic sum because its subpart `(Foo.B : Foo) & (Foo.A : Foo)` is an intersection of unrelated definitions value B and value A. |
This file contains hidden or 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,32 @@ | ||
import scala.deriving.Mirror | ||
|
||
sealed trait Lst[+A] // AKA: scala.collection.immutable.List | ||
case class Cns[+A](head: A, tail: Lst[A]) extends Lst[A] | ||
case object Nl extends Lst[Nothing] | ||
|
||
sealed trait Opt[+A] // AKA: scala.Option | ||
case class Sm[+A](value: A) extends Opt[A] | ||
case object Nn extends Opt[Nothing] | ||
|
||
enum Foo: | ||
case A, B | ||
|
||
object Bar: | ||
val A: Foo.A.type = Foo.A // alias of Foo.A | ||
type A = Foo.A.type // type alias | ||
|
||
case object Baz | ||
type Baz = Baz.type | ||
|
||
val testA = summon[Mirror.ProductOf[Cns[Int] & Sm[Int]]] // error: unreleated | ||
val testB = summon[Mirror.ProductOf[Sm[Int] & Cns[Int]]] // error: unreleated | ||
val testC = summon[Mirror.Of[Cns[Int] & Sm[Int]]] // error: unreleated | ||
val testD = summon[Mirror.Of[Sm[Int] & Cns[Int]]] // error: unreleated | ||
val testE = summon[Mirror.ProductOf[Sm[Int] & Nn.type]] // error: unreleated | ||
val testF = summon[Mirror.ProductOf[Nn.type & Sm[Int]]] // error: unreleated | ||
val testG = summon[Mirror.Of[Foo.A.type & Foo.B.type]] // error: unreleated | ||
val testH = summon[Mirror.Of[Foo.B.type & Foo.A.type]] // error: unreleated | ||
val testI = summon[Mirror.Of[Foo.A.type & Bar.A.type]] // ok | ||
val testJ = summon[Mirror.Of[Bar.A.type & Foo.A.type]] // ok | ||
val testK = summon[Mirror.Of[Foo.A.type & Bar.A.type & Bar.A]] // ok | ||
val testL = summon[Mirror.Of[Baz & Baz.type]] // ok |
This file contains hidden or 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,19 @@ | ||
import scala.deriving.Mirror | ||
|
||
trait Mixin | ||
object Mixin | ||
|
||
trait Parent | ||
object Parent | ||
|
||
sealed trait Fruit extends Parent | ||
object Fruit { | ||
case object Apple extends Fruit | ||
case object Orange extends Fruit | ||
} | ||
|
||
@main def Test = { | ||
val mFruit = summon[Mirror.SumOf[Fruit & Parent]] | ||
assert(mFruit.ordinal(Fruit.Apple) == 0) | ||
assert(mFruit.ordinal(Fruit.Orange) == 1) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.