Repository navigation
Ensure override compatibility with type variables - #171
Conversation
cpovirk
left a comment
There was a problem hiding this comment.
I will organize some thoughts, but I am all for merging even a hacky fix.
|
Again, LGTM. I will test this in the Google codebase and report back, but I don't think that even that is a blocker for merging. (If I discover that things somehow break as a result, we can always revert the commit :)) My next thought is that it does seem that this new case "shouldn't be necessary": Ah, I wonder if somehow those are two different Anyway, I've now talked myself into at least sort of having a theory about what's going on. And if that theory is right, your fix is probably the best we can do on the jspecify-reference-checker side. If so, it's still possible that something more can be done on the checker-framework side. But I wouldn't worry about it: There's still a decent chance that we end up redoing some of this code as a result of changes in design decisions and/or to make it fit more naturally into the Checker Framework model (instead of having this extensive |
|
It looks like I may be seeing fewer "incompatible parameter type" errors, albeit still not zero. It's a bit hard to tell how much of the reduction is because of #159 crashes that hide other problems, but clearly at least some of the reduction is real. An example of a line on which I'm still seeing a problem is this one: Both the "found" type and the "required" type are "Multimap<? extends K, ? extends V>." |
|
The remaining issue might be restricted to type parameters that extend other type parameters (and, similarly, wildcards that extend type parameters). Here's an example: import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
class Issue164Continued {
interface Super<T extends @Nullable Object> {
<U extends T> void foo(Lib<? extends U> lib);
}
interface Sub<T extends @Nullable Object> extends Super<T> {
<U extends T> void foo(Lib<? extends U> lib);
}
interface Lib<T extends @Nullable Object> {}
}It's a rare enough problem that I'd feel OK with adding suppressions for it. (I could believe that a proper fix would involve more |
|
(Well, I guess we'll see how common it really is after the crashes are gone. Maybe it's worse than I think.) |
|
At a higher level:
|
…hecker into issue-164
|
@cpovirk Thanks for the additional test! I like using different type variable names for different type variable declarations. That makes it easier to see in messages that it is looking at different types. The If this is producing okay results, I would propose merging and cleaning up the CF interaction and wonkiness separately. |
| // Work around wonkyness of CF override checks. | ||
| AnnotatedTypeVariable subTV = (AnnotatedTypeVariable) subtype; | ||
| if (isCapturedTypeVariable(subTV.getUnderlyingType())) { | ||
| subTV = (AnnotatedTypeVariable) subTV.getUpperBound(); |
There was a problem hiding this comment.
It looks like we'd need to check that assumption:
Exception: java.lang.ClassCastException: class org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedDeclaredType cannot be cast to class org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedTypeVariable
That error is probably happening at https://github.com/google/auto/blob/68d99dc75b8379ca14e56c8c4f10493b1b0cb38d/common/src/main/java/com/google/auto/common/SuperficialValidation.java#L237.
I think we're fine just not worrying about trying to handle the captured-type-variable case at all for now. But if you want to look into it more, I can get you more information tomorrow. Let me know.
There was a problem hiding this comment.
Ah! I added a check to ensure the cast is safe.
There was a problem hiding this comment.
I've confirmed (a) that it eliminates all the crashes I was seeing and (b) that the overall change does address the ? extends E errors I was seeing.
I want to look whether there is a better fix for this, maybe by moving this check into the override checker.
Instead, maybe something is wrong with the logic in the
returnstatement that follows this change.Let me know if this looks familiar.
Fixes #164.