-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Mirror.Product is available for enum values that are not subtypes of Product #9011
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
I think |
Fix #9011: Make single enum values inherit from Product
This is now fixed, but I'm leaving this issue open because the original issue remains I think:
@milessabin Is this cast supposed to be safe? If not, the doc example needs to be fixed. |
Yes it is. |
I believe that this should be ok to close - I don't think ProductOf will be synthesised unless the underlying type extends Product (invariant, not checked), but we could add an assertion |
I'm not sure if this is intentional, but it certainly caught me by surprise.
From the example in the documentation (https://dotty.epfl.ch/docs/reference/contextual/derivation.html):
We can summon a
Mirror.Product
for both cases of the enum, butOpt.Nn
is not a subtype ofProduct
.The example in the docs suggests that if we have a
Mirror.ProductOf[T]
then we can safely cast an instance ofT
toProduct
(in order to accessproductIterator
etc.). But this is not the case.Indeed, if we add a line to the test in the example:
then it throws a ClassCastException at runtime.
Minimized example
(taken from the docs, with a couple of tweaks to make it compile)
Output
Suggested fix
Maybe a documentation fix is sufficient here? i.e. fix the example to avoid the incorrect cast, and add a note about when
enum
cases do or do not extendProduct
.The text was updated successfully, but these errors were encountered: