Skip to content
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

Merged
merged 1 commit into from
Feb 21, 2025

Conversation

jchyb
Copy link
Contributor

@jchyb jchyb commented Nov 26, 2024

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).

Comment on lines 2526 to 2528
typeRepr match
case AppliedType(_, Nil) => isArray
case _ => isArray
Copy link
Member

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 ?

Copy link
Contributor Author

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.

@jchyb jchyb force-pushed the fix-i21916-array-check branch from 164a8ed to 80ae408 Compare January 9, 2025 11:15
Copy link
Member

@hamzaremmal hamzaremmal left a 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).

@hamzaremmal
Copy link
Member

@jchyb The current check for Predef.classOf:

def checkClassType(tp: Type, pos: SrcPos, traitReq: Boolean, stablePrefixReq: Boolean, refinementOK: Boolean = false)(using Context): Type =

@hamzaremmal hamzaremmal assigned jchyb and unassigned hamzaremmal Feb 21, 2025
@jchyb
Copy link
Contributor Author

jchyb commented Feb 21, 2025

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.

Copy link
Member

@hamzaremmal hamzaremmal left a 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.

@hamzaremmal hamzaremmal merged commit 595c5d7 into scala:main Feb 21, 2025
29 checks passed
@hamzaremmal hamzaremmal deleted the fix-i21916-array-check branch February 21, 2025 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

assertion failed: class Array while introspecting Array[Byte] in a macro
2 participants