-
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 #15231 from dotty-staging/fix-15222
fix #15222 recursively check for product ctor accessibility
- Loading branch information
Showing
9 changed files
with
164 additions
and
85 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
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,8 +1,8 @@ | ||
-- Error: tests/neg/i14025.scala:1:88 ---------------------------------------------------------------------------------- | ||
1 |val foo = summon[deriving.Mirror.Product { type MirroredType = [X] =>> [Y] =>> (X, Y) }] // error | ||
| ^ | ||
|No given instance of type deriving.Mirror.Product{MirroredType[X] = [Y] =>> (X, Y)} was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Product{MirroredType[X] = [Y] =>> (X, Y)}: class Tuple2 is not a generic product | ||
|No given instance of type deriving.Mirror.Product{MirroredType[X] = [Y] =>> (X, Y)} was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Product{MirroredType[X] = [Y] =>> (X, Y)}: type [X] =>> [Y] =>> (X, Y) is not a generic product because its subpart [X] =>> [Y] =>> (X, Y) is not a supported kind (either `*` or `* -> *`) | ||
-- Error: tests/neg/i14025.scala:2:90 ---------------------------------------------------------------------------------- | ||
2 |val bar = summon[deriving.Mirror.Sum { type MirroredType = [X] =>> [Y] =>> List[(X, Y)] }] // error | ||
| ^ | ||
|No given instance of type deriving.Mirror.Sum{MirroredType[X] = [Y] =>> List[(X, Y)]} was found for parameter x of method summon in object Predef | ||
|No given instance of type deriving.Mirror.Sum{MirroredType[X] = [Y] =>> List[(X, Y)]} was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Sum{MirroredType[X] = [Y] =>> List[(X, Y)]}: type [X] =>> [Y] =>> List[(X, Y)] is not a generic sum because its subpart [X] =>> [Y] =>> List[(X, Y)] is not a supported kind (either `*` or `* -> *`) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import scala.deriving.Mirror | ||
|
||
package lib { | ||
sealed trait Foo | ||
object Foo // normally, would cache a mirror if one exists. | ||
case class Bar private[lib] () extends Foo | ||
case object Bar // force mirror for Bar to be anonymous. | ||
|
||
|
||
object CallSiteSucceed { | ||
val mFoo = summon[Mirror.SumOf[lib.Foo]] // ok | ||
val mBar = summon[Mirror.ProductOf[lib.Bar]] // ok | ||
} | ||
|
||
} | ||
|
||
package app { | ||
|
||
object MustFail { | ||
// we are outsite of accessible scope for Bar's ctor, so this should fail. | ||
|
||
val mFoo = summon[Mirror.SumOf[lib.Foo]] // error | ||
val mBar = summon[Mirror.ProductOf[lib.Bar]] // error | ||
} | ||
|
||
} |
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 @@ | ||
import scala.deriving.Mirror | ||
|
||
package lib { | ||
enum Foo: | ||
case A | ||
|
||
case object Bar | ||
} | ||
|
||
package app { | ||
object Foo: | ||
val A: lib.Foo.A.type = lib.Foo.A | ||
val Bar: lib.Bar.type = lib.Bar | ||
} | ||
|
||
|
||
@main def Test = | ||
assert(summon[Mirror.Of[scala.Nil.type]].fromProduct(EmptyTuple) == Nil) // alias scala 2 defined | ||
assert(summon[Mirror.Of[lib.Foo.A.type]].fromProduct(EmptyTuple) == lib.Foo.A) // real mirror | ||
assert(summon[Mirror.Of[lib.Bar.type]].fromProduct(EmptyTuple) == lib.Bar) // real mirror | ||
assert(summon[Mirror.Of[app.Foo.A.type]].fromProduct(EmptyTuple) == lib.Foo.A) // alias mirror | ||
assert(summon[Mirror.Of[app.Bar.type]].fromProduct(EmptyTuple) == lib.Bar) // alias mirror |
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,15 @@ | ||
package lib | ||
|
||
import scala.deriving.Mirror | ||
|
||
sealed trait Foo | ||
object Foo // normally, would cache a mirror if one exists. | ||
case class Bar private[lib] () extends Foo | ||
case object Bar // force mirror for Bar to be anonymous. | ||
|
||
|
||
object CallSiteSucceed { | ||
val mFoo = summon[Mirror.SumOf[Foo]] // ok | ||
val mBar = summon[Mirror.ProductOf[Bar]] // ok | ||
val sampleBar = Bar() | ||
} |
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,6 @@ | ||
@main def Test = | ||
assert(lib.CallSiteSucceed.mFoo eq lib.Foo) // binary compatibility with 3.1 | ||
assert(lib.CallSiteSucceed.mBar ne lib.Bar) // anonymous mirror | ||
|
||
assert(lib.CallSiteSucceed.mFoo.ordinal(lib.CallSiteSucceed.sampleBar) == 0) | ||
assert(lib.CallSiteSucceed.mBar.fromProduct(EmptyTuple) == lib.CallSiteSucceed.sampleBar) |