-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Missing arity check in fromProduct for Tuples #15399
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
we can patch this for newly compiled code but its still not going to work when depending on libraries compiled by 3.1.x - but |
What I would propose is instead of generating a new anonymous class for each tuple mirror we could define a class in the library. Right now we do val tup2Mirror =
{
final class $anon() extends Object(), Serializable {
type MirroredMonoType = (Int, Int) // not sure why this is added here
}
(new $anon():Object & Serializable)
}.$asInstanceOf[
scala.deriving.Mirror.Product{
MirroredMonoType = (Int, Int); MirroredType = (Int, Int);
MirroredLabel = ("Tuple2" : String)
; MirroredElemTypes = (Int, Int);
MirroredElemLabels = (("_1" : String), ("_2" : String))
}
] instead we could define in the library runtime package scala.runtime
class TupleMirror(arity: Int) extends Mirror.Product {
def fromProduct(p: scala.Product): MirroredMonoType =
assert(p.productArity == arity, "...")
Tuple.fromProduct(p).asInstanceOf[MirroredMonoType]
} and then we can infer val tup2Mirror =
new runtime.TupleMirror(2).$asInstanceOf[
scala.deriving.Mirror.Product{
MirroredMonoType = (Int, Int); MirroredType = (Int, Int);
MirroredLabel = ("Tuple2" : String)
; MirroredElemTypes = (Int, Int);
MirroredElemLabels = (("_1" : String), ("_2" : String))
}
] |
This also made me notice that the tuple mirrors are extremely inefficient as each inferred instance creates a new class with a duplication of the same code. This would be solved by the |
Furthermore, the |
this sounds good to me - I didn't quite get before that this change was just for tuples. - and the |
We could add the |
Compiler version
438dfb0
Minimized code
Output
Expectation
fromProduct
should assert that the arity of the given tuple is correct. It should fail with a meaningful error message.The text was updated successfully, but these errors were encountered: