-
Notifications
You must be signed in to change notification settings - Fork 119
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
Inconsistent behavior for new array of Number with numeric initializers #47
Comments
Upon further investigation, I was able to make the code work applying the following changes to the code base:
if (sourceType.isInterface() || // interface cast
targetType.isInterface() ||
sourceType == Types.Object || // boxing cast
targetType == Types.Object ||
(!targetType.isPrimitive() && !sourceType.isPrimitive() && TypeUtils.isNumeric(sourceType) && targetType.isAssignableFrom(sourceType))) { // super cast (e.g. Double -> Number)
emitCastToType(sourceType, targetType);
} to ensure that a cast is emitted for a numeric type to a superclass of the boxed reference.
if (!TypeUtils.areReferenceAssignable(elementType, TypeUtils.getBoxedTypeOrSelf(item.getType()))) {
throw Error.expressionTypeCannotInitializeArrayType(item.getType(), elementType);
} With these modifications, the above tests complete (and no regression appears in existing ones, as far as I could see). |
Will look into this in greater detail later, but this did catch my eye: I don't think By the way, you've been submitting a lot of bug reports related to procyon-expressions (which is great!). May I ask how you've been using it? I get very little info about who's using the various Procyon libraries apart from the number of downloads on my decompiler. |
To be honest, I think that an implicit conversion between primitive and Number is a bit of a stretch too, but it was quite handy! In my case, I am using Procyon to implement some sort of configurable processing framework. I could have used a full-fledged scripting engine (or maybe Groovy), but this way I can implement some handy features to simplify/shorten the configuration or use language features not available in Java (my main background is C#, so conditional access operator, coalesce operator and extension methods are something I miss dearly). |
Cool project! You may want to go ahead and check out my
These are, unfortunately, necessary, as the method I used to define classes dynamically has been deprecated and removed. As far as I can tell, you can no longer declare new classes in an arbitrary package (unless you resort to custom class loaders). |
I had a look at that, and it seems really good! I have a fork here on GitHub, were I ported the project to Grade 7 (and was about to update JUnit to version 5), but I could not check signing. If you are interested, I can make a WIP PR to let you review and check it. |
Numeric types are not handled consistently when trying to initialize arrays.
In general, trying to initialize a
Number[]
fails with both primitive and reference numeric types, but with different errors.Below a couple of test to reproduce the issue:
Attached the full test class.
Notice that both initializations (with or without primitive types) are legal in Java, but in Procyon
The tests show that using an
Object[]
results in the same behavior, while assignment betweenNumber
/Object
and numeric primitives/references works fine.The text was updated successfully, but these errors were encountered: