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

review: fix: Subtyping relationships for arrays #5466

Merged
merged 2 commits into from
Sep 27, 2023

Conversation

I-Al-Istannen
Copy link
Collaborator

This one was a bit of a doozy.

Array subtyping needs to be special cased, as Spoon is not able to build a CtType for source-level arrays. Similarly, once we are given a shadow CtType that refers to an array type, we need to unpack to find the real type to build our hierarchy for. We can not just fall back to the java Class#isAssignableFrom, as the super type reference might not be shadowable.

Closes #5462.

throw new SpoonException("There are no source level array type declarations");
}
Class<?> actualClass = base.getActualClass();
// Arrays of different shapes are not subtypes
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't true?

new Object[0][0] instanceof Object[]
$3 ==> true

This is a consequence of

  • If S and T are both reference types, then S[] >1 T[] iff S >1 T.
  • Object >1 Object[]

unless I'm missing some context here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, I missed that when reading the rules apparently. That is a bit unfortunate. I guess I need to peel of layers until one or the other reaches a non-array value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed (hopefully :P). Thanks :)

@I-Al-Istannen I-Al-Istannen changed the title fix: Subtyping relationships for arrays review: fix: Subtyping relationships for arrays Sep 25, 2023
@SirYwell SirYwell merged commit e777ea7 into INRIA:master Sep 27, 2023
@SirYwell
Copy link
Collaborator

Thanks!

@I-Al-Istannen I-Al-Istannen deleted the fix/issue-5462 branch September 27, 2023 18:32
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 this pull request may close these issues.

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