Skip to content

Do precise subtype tests in instanceof #2588

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

Merged
merged 16 commits into from
Dec 14, 2022
Merged

Do precise subtype tests in instanceof #2588

merged 16 commits into from
Dec 14, 2022

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Dec 8, 2022

Addresses #2577. One rather trivial part of the issue was that previously, since interfaces are not derived from Object but their implementing classes are, an someInterface as Object instanceof SomeInterface would fail. Another was that the check for when a cast may possibly succeed was overly simplistic, thus required more elaborate infrastructure.

The seemingly obvious alternative that doesn't work is to simply fall back to do dynamic checks if the relationship between the types is arbitrarily complicated (and hence possibly costly to compute), since that breaks assumptions about such checks being precomputable.

Making a draft for now while I untie the knot in my brain before figuring out how to best test the changes. Is perfectly possible that I missed something, hence I'd appreciate any amount of eyes on the new logic :)

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

Copy link
Member

@CountBleck CountBleck left a comment

Choose a reason for hiding this comment

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

I don't really get this stuff, so I can't help much :)

@dcodeIO
Copy link
Member Author

dcodeIO commented Dec 13, 2022

So I wasn't quite happy with the previous take and decided to refactor this more. Now, extendees and implementers are populated early using a bunch of ugly loops that are probably less ugly than frequent recursion, so the checks, whereof there may be many, are just hash map lookups.

@dcodeIO dcodeIO marked this pull request as ready for review December 14, 2022 15:07
@dcodeIO dcodeIO merged commit 78b3260 into main Dec 14, 2022
@HerrCai0907 HerrCai0907 deleted the issue-2577 branch October 17, 2023 09:00
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.

2 participants