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

[Bug]: ctArrayTypeReference.isSubtypeOf(...) returns true if the array type is a subtype #5462

Closed
Luro02 opened this issue Sep 22, 2023 · 0 comments · Fixed by #5466
Closed
Labels

Comments

@Luro02
Copy link
Contributor

Luro02 commented Sep 22, 2023

Describe the bug

Obviously Integer[] is not a Number.

Source code you are trying to analyze/transform

public class Test { Integer[] field; }

Source code for your Spoon processing

import org.junit.jupiter.api.Test;
import spoon.Launcher;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtType;
import spoon.reflect.reference.CtArrayTypeReference;
import spoon.reflect.reference.CtTypeReference;

import static org.junit.jupiter.api.Assertions.*;

class TestSpoon {
    @Test
    void testArraySubtype() {
        CtField<?> ctField = Launcher.parseClass("public class Test { Integer[] field; }")
            .getField("field");

        CtTypeReference<?> ctArrayType = ctField.getType();

        assertTrue(ctArrayType instanceof CtArrayTypeReference<?>, "ctArrayType should be an instance of CtArrayTypeReference");
        assertFalse(
            ctArrayType.isSubtypeOf(ctField.getFactory().Type().get(java.lang.Number.class).getReference()),
            "an array of integers should not be a subtype of Number"
        );
    }
}

Actual output

org.opentest4j.AssertionFailedError: an array of integers should not be a subtype of Number ==> 
Expected :false
Actual   :true

Expected output

No response

Spoon Version

10.4.1-SNAPSHOT

JVM Version

openjdk version "17.0.1" 2021-10-19 OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12) OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)

What operating system are you using?

Windows 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant