-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Mirror.Sum not synthesised for base class without companion #10997
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
Comments
If this is not considered a bug, at least would be nice to have a better error message explaining this is a nested class |
I investigated by printing the internal reporting and the reason given for not generating a mirror is that
So the example can be fixed by instead defining the child cases within a companion object, such as this: class Test {
sealed trait Role
object Role {
case object Admin extends Role
case class Contributor(organization: String) extends Role
}
println(summon[deriving.Mirror.Of[Role]])
} I will update with why changing |
Basically, following the code of the accessibility test in the above comment, I think it is a bug that it works when |
Hi Jamie thanks for the fast feedback, but allow me to disagree... In the scaladoc of that method: The important bit is "all of its children are addressable through a path from its companion object". And if we try that "manually" it compiles: class Main {
sealed trait Role
case object Admin extends Role
case class Contributor(organization: String) extends Role
object Role {
val r: Role = ???
val a: Admin.type = ???
val c: Contributor = ???
}
} So all the children are addressable from the companion object... |
Ok right yes that would make sense, so only defining the companion object is required: class Test {
sealed trait Role
case object Admin extends Role
case class Contributor(organization: String) extends Role
object Role
println(summon[deriving.Mirror.Of[Role]])
} because |
oh thats a very nice workaround. should we close this? or should this be fixed? maybe there is a way that the compiler could generate the companion object behind the scenes? |
In my opinion, based on the test cases in #6531, it is a bug that |
One reason this may have gone unnoticed for so long is that using a |
tests https://github.com/lampepfl/dotty/blob/master/tests/run/deriving.scala and https://github.com/lampepfl/dotty/blob/master/tests/run/deriving-constructor-order.scala work on the assumption that a companion is not required, which makes the motivation for this accessible from companion test confusing |
I have found this commit: 275a0a9 i.e. the message is "Generate sum mirrors for sealed traits that do not have a companion" so it would seem pretty clear that it is infact the original code example which is a bug: class Test {
sealed trait Role
case object Admin extends Role
case class Contributor(organization: String) extends Role
println(summon[Mirror.Of[Role]]) // should be able to find the Mirror but can't
} |
fix #10997: check accessible from sealed parent not companion
Minimized code
Output
// no implicit argument of type deriving.Mirror.Of[Test.this.Role] was found for parameter x of method summon in object Predef
Expectation
It should be able to derive the mirror as if it was inside the companion object.
I found this while I was port play-json to dotty (https://github.com/playframework/play-json/pull/555/files).
The text was updated successfully, but these errors were encountered: