-
Notifications
You must be signed in to change notification settings - Fork 19
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 #1049
base: master
Are you sure you want to change the base?
Changes from all commits
298df8a
c4588df
82740f7
d71ead6
0dec947
f5c5d22
c916493
bfa5794
93a6a1a
b04007c
9b116a7
b88949f
361f487
874e594
09904ba
9862649
b8f1549
deffd1d
4f476f2
f82dc77
efeeea2
c34285f
16d69a6
4cd7e9a
cb0cb64
d7429e4
8502489
72e074e
1cfd105
e92f0c6
0658def
7991a8b
4ffe0f1
fa1439e
a15d727
bfee453
20d62af
8e0f908
91b22c9
09cc33d
24105c4
c2bea34
1ec438e
a6fb6ce
724a95e
d241446
07eaacb
4229827
fc9ad98
d06ad1f
f4ffe07
ac60c2e
0115fbe
67ba76b
0b78587
1b8f4ab
2d969fc
1b20546
b94311d
98060e3
f4d4ec1
0831233
ff15156
96ec55e
b33c202
875a099
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,9 @@ void StringIsGBnothing( | |
@GuardSatisfied Object o3, | ||
@GuardedByBottom Object o4) { | ||
String s1 = (String) o1; | ||
// :: error: (cast.incomparable) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incompatible with the comment on line 9 - there should be no errors in this method. |
||
String s2 = (String) o2; | ||
// :: error: (cast.incomparable) | ||
String s3 = (String) o3; | ||
String s4 = (String) o4; // OK | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import org.checkerframework.checker.signedness.qual.Signed; | ||
import org.checkerframework.checker.signedness.qual.SignednessGlb; | ||
import org.checkerframework.checker.signedness.qual.UnknownSignedness; | ||
|
||
class CastFromTtoT<T extends @UnknownSignedness Object> { | ||
@SuppressWarnings("unchecked") | ||
T bar(@UnknownSignedness Object p) { | ||
// Seems to have no cast in terms of the qualifier (from @UnknownSignedness to | ||
// @UnknownSignedness), but in instantiation, it could be a downcast. | ||
// See method foo below. It's okay not to report downcast warnings as Javac will warn about | ||
// casting object to 'T' (unchecked warning) | ||
T x = (T) p; | ||
return x; | ||
} | ||
|
||
void foo(CastFromTtoT<@Signed Integer> s, @UnknownSignedness Object local) { | ||
// Here, we passed in an @UnknownSignedness object and the method signature after | ||
// substitution is @Signed Integer bar(@UnknownSignedness Object). This makes the typecast | ||
// discussed earlier a downcast. | ||
@Signed Integer x = s.bar(local); | ||
} | ||
|
||
class Inner<T extends @UnknownSignedness Object> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename the type parameter |
||
T bar2(@Signed T p) { | ||
// The casting expression below looks like an upcast (in terms of the qualifier), | ||
// but it could be a downcast in invocation (See method foo2 below for an example). | ||
// We should report downcast warning if there is one because | ||
// Javac doesn't warn when casting a variable from type T to T. | ||
// :: warning: (cast.unsafe) | ||
T x = (T) p; | ||
return x; | ||
} | ||
|
||
void foo2(Inner<@SignednessGlb Integer> s, @Signed Integer local) { | ||
// Here, we passed in an @Signed integer and the method signature after | ||
// substitution is @SignednessGlb Integer bar2(@Signed Object). This makes the typecast | ||
// discussed in method bar2 a downcast. | ||
@SignednessGlb Integer x = s.bar2(local); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change make sense to you?
@UnknownInitialization
is the top of this hierarchy and@Initialized
is a subtype. So why isn't this stillcast.unsafe
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this error message is for
@Initialized CastInit t2 = (@Initialized CastInit) this;
and as this is in the constructor, sothis
is@UnderInitialization
and is casting to@Initialized
, so the cast is incomparable.