-
Notifications
You must be signed in to change notification settings - Fork 1.1k
generic tuple not of subtype of ProductN #15253
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
This is consistent with the current design as |
Maybe the mirrors could return |
I don't know the compiler good enough to anticipate the results, but I think it is rather useful feature in absence of the traditional "unapply". My use case are circe's Encoder#forProductN, which require a function from (case class) instance to ProductN. Are there other possibilities to implement that trivially or should that interface be changed? |
One of the long terms goals of generic tuples is to make the
It seems that you need to use mirrors to implement that. What does |
Sounds promising :)
You can encode any object as JSON by mapping it to a product (tuple) of objects which can be encoded by other means. |
But why does the assignment to x work, then? If fromProductTyped returns (Int, String) which is not <:< Tuple2[…], the variable type should mismatch. |
It's really.... shall we say, disquieting that the subtyping here isn't transitive: scala> summon[Int *: Int *: EmptyTuple <:< Tuple2[Int, Int]]
val res11: (Int, Int) =:= (Int, Int) = generalized constraint
scala> summon[Tuple2[Int, Int] <:< Product2[Int, Int]]
val res12: (Int, Int) =:= (Int, Int) = generalized constraint
scala> summon[Int *: Int *: EmptyTuple <:< Product2[Int, Int]]
-- Error: ----------------------------------------------------------------------
1 |summon[Int *: Int *: EmptyTuple <:< Product2[Int, Int]]
| ^
| Cannot prove that (Int, Int) <:< Product2[Int, Int].
1 error found 🙀 It's rather cold comfort to know that |
Is that the future design or the current design? They seem currently equal to me:
|
Agreed - I'm struggling to see how this issue is an “enhancement” rather than a bug. |
Fixing this could make it a lot easier to move away from derivation. This seems like it should compile: case class Foo(x: Int, y: String)
val t: Tuple2[Int, String] = Tuple.fromProductTyped(Foo(1, "a"))
val p1: Product2[Int, String] = p1
// fails to compile: Found (Int, String); required Product2[Int, String]
val p2: Product2[Int, String] = Tuple.fromProductTyped(Foo(1, "a")) |
Compiler version
3.1.2
Minimized code
Output
Expectation
As (A, B) = Tuple2[A, B] is a direct subclass of Product2[Int, String], I would expect that the assignment to z compiles.
The text was updated successfully, but these errors were encountered: