-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add a check for correct Array shape in quotes.reflect.ClassOfConstant #22033
Conversation
typeRepr match | ||
case AppliedType(_, Nil) => isArray | ||
case _ => isArray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a pattern matching if both branches have a similar result ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot about case AppliedType(_, _) where we would not check isArray
. I've adjusted this to be clearer anyway.
164a8ed
to
80ae408
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should follow the specification of classOf
here. Even if it doesn't create any issues in later phases, we should not allow types that are not proper types (*
-kind).
@jchyb The current check for
|
I agree, and in a ideal world that would be the case, but that's something I am personally very conflicted about - adding a check like this would completely break Izumi reflect (they always strip the type arguments, for whatever reason), and thus any zio libraries that use it (I unfortunately did also end up using Izumi-reflect in other migrations, since it's pretty much the only alternative to the deprecated TypeTag from scala 2). I wanted the change here to have as small of a footprint as possible, while still being helpful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jchyb Can you please open an issue to track the fact that we need to add the "correct" check eventually and add it to the backlog.
Closes #21916
I tried to supply the ClassOfConstant with multiple other broken Types, but I was unable to break it beyond the linked issue, so I ended up adding the check for only that one case. This makes sense - the backend (and thus erasure) needs to know if the Array type parameter is a primitive type, but in other cases the erasure phase needs to know only the class, without the type parameters.
It's impossible to call classOf through the quoted code (
'{classOf[t]}
with a boundless t will error out), so we don't need that additional check there.There does appear to be an issue with being able to set
'{List[Array]}
resulting in a crash, but that is beyond the scope of this fix - I will prepare a separate issue for that (edit: reported here).