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

Improve cast warnings/errors logic #337

Closed
wants to merge 63 commits into from

Conversation

AndrewShf
Copy link
Member

@AndrewShf AndrewShf commented Sep 21, 2022

Fixes #155.
Merge together with eisop-codespecs/daikon#2.

This PR aims at refining the typecasting logic in Checker-Framework.

  1. some downcasts can be statically verified and should not issue a warning or error. Suppose we are casting a @top base variable to @bot derived type, both the pluggable types and java types are downcasting, and suppose derived class can only be annotated with @bot. we believe this kinds of downcasts can be statically verified in checkerframework. Case1: If base is really a derived instance and this instance could only be annotated with @bot, it's okay we cast from top to bot; Case2: if base is not a derived instance, and we can rely on javac or java-runtime to report a inconvertible types or classcastexception.
  2. some typecasts which can't be verified should throw an error instead of a warning, like said in Casting incomparable types should raise an error instead of a warning #155.

Enumerate all the conditions:
Screen Shot 2022-09-12 at 11 06 43 AM

Main logic:

Screen Shot 2022-08-07 at 9 19 44 PM

method isUpcast(...) logic:

Screen Shot 2022-08-07 at 9 35 14 PM

isSafeDowncast logic:

Screen Shot 2022-08-07 at 9 41 45 PM

isSafeIncomparableCast() logic:
Screen Shot 2022-08-07 at 9 42 43 PM

@AndrewShf AndrewShf requested review from wmdietl and removed request for wmdietl September 21, 2022 22:10
@sonatype-lift
Copy link

sonatype-lift bot commented Nov 1, 2022

⚠️ 97 God Classes were detected by Lift in this project. Visit the Lift web console for more details.

@AndrewShf
Copy link
Member Author

AndrewShf commented Sep 28, 2023

checkCastElementType is mentioned in the manual and linked to two other places which doesn't mention the option at all.
should file an issue to add a new subsection to illustrate the typecasting and the option. #575

@AndrewShf AndrewShf assigned wmdietl and unassigned AndrewShf Sep 29, 2023
Copy link
Member

@wmdietl wmdietl left a comment

Choose a reason for hiding this comment

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

Thanks for all your work on this! I have a few questions about naming and how to structure this change.

* @param v2 a type variable
* @return whether the arguments are the same type variables
*/
public static boolean areSameTypeVariables(TypeVariable v1, TypeVariable v2) {
Copy link
Member

Choose a reason for hiding this comment

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

This method seems very dangerous... can you add a warning to the method. I think this only works if the TypeVariables are from the same context. If one compares TVs from e.g. a declaration to a TV from a use site, there could be two different Ts that just happen to have the same name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing this out! I will leave a comment there.

@wmdietl wmdietl assigned AndrewShf and unassigned wmdietl Oct 1, 2023
@AndrewShf AndrewShf assigned wmdietl and unassigned AndrewShf Oct 3, 2023
@wmdietl
Copy link
Member

wmdietl commented Jan 5, 2025

Further updates in #1049.

@wmdietl wmdietl closed this Jan 5, 2025
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.

Casting incomparable types should raise an error instead of a warning
3 participants