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

int literals should return an Integer value #624

Merged
merged 3 commits into from
Jan 11, 2025

Conversation

timtebeek
Copy link
Contributor

What's changed?

What's your motivation?

As discovered on

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions could not be made:

  • src/main/java/org/openrewrite/kotlin/KotlinTypeGoat.kt
    • lines 25-25
  • src/test/resources/KotlinTypeGoat.kt
    • lines 25-25

@timtebeek
Copy link
Contributor Author

Thanks yes that looks to be it! Now we have to see at which point we can alter that value :)

@barbulescu
Copy link

Maybe here:

    @Override
    public J visitConstantExpression(KtConstantExpression expression, ExecutionContext data) {
        IElementType elementType = expression.getElementType();
        Object value;
        if (elementType == KtNodeTypes.INTEGER_CONSTANT || elementType == KtNodeTypes.FLOAT_CONSTANT) {
            value = ParseUtilsKt.parseNumericLiteral(expression.getText(), elementType);
            if (value instanceof Long) {
                int intValue = ((Long) value).intValue();
                if (Objects.equals(value, (long) intValue)) {
                    value = intValue;
                }
            }
        } else if (elementType == KtNodeTypes.BOOLEAN_CONSTANT) {

@timtebeek
Copy link
Contributor Author

Nice, thanks! Went for a slightly different approach to ensure true longs remain longs. With that I think we're good! :)

@timtebeek timtebeek marked this pull request as ready for review January 11, 2025 21:22
@timtebeek timtebeek merged commit 181a00d into main Jan 11, 2025
2 checks passed
@timtebeek timtebeek deleted the demonstrate-primited-type-issue branch January 11, 2025 21:25
@barbulescu
Copy link

Kotlin forum is in read-only mode so I created a bug report.

@timtebeek
Copy link
Contributor Author

Much appreciated! I'll have another look at your PR in rewrite-spring now that this is sorted. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-kotlin
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants