-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix lower bound of type variables and unspecified subtypes. #175
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9fef70b
Adapt to changes in https://github.com/eisop/checker-framework/pull/739
wmdietl d3198a3
Add regression test case; adapt to API changes
wmdietl 9c70df2
Remove accesses and assertions that are no longer needed.
wmdietl 4011143
Run the regression tests
wmdietl c8a671e
Include "kind" in output; remove debugging output
wmdietl f44acb0
Adapt nullness annotation/comment; undo changes to hashCode/equals.
wmdietl 651689e
Fix lower bound of type variables and unspecified subtypes.
wmdietl 8a40027
Merge branch 'main-eisop' of github.com:jspecify/jspecify-reference-c…
wmdietl 9e27b8f
Use suggested alternative implementation
wmdietl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 The JSpecify Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Test case for Issue 172: | ||
// https://github.com/jspecify/jspecify-reference-checker/issues/172 | ||
|
||
import org.jspecify.annotations.NullMarked; | ||
|
||
class Issue172<E> { | ||
E e() { | ||
return null; | ||
} | ||
} | ||
|
||
class Issue172UnmarkedUse { | ||
void foo(Issue172<Object> p) {} | ||
} | ||
|
||
@NullMarked | ||
class Issue172MarkedUse { | ||
void foo(Issue172<Object> p) {} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The order of
TypeUseLocation
enums matters and they are applied in declaration order.I think what is happening is that the
IMPLICIT_LOWER_BOUND
default is applied first and then theTYPE_VARIABLE_USE
has nothing left to do.The inconsistency between the two constants is confusing anyways, so I think it makes sense to move this here.
I've filed eisop/checker-framework#741 to think more about this.
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.
On eisop/checker-framework#741:
Ah, I do remember issues with the ordering, now that you mention it, probably as documented here:
jspecify-reference-checker/src/main/java/com/google/jspecify/nullness/NullSpecAnnotatedTypeFactory.java
Lines 843 to 847 in fae43cf
(And of course this is what the "Ensure that all locations that appear in the
defaultLocations
" comment above is saying, too. So I'm not saying anything new here :))In that case, I wanted to override a specific location's value from an enclosing type with a general value at a smaller scope. As a result, I had to also override the specific location's value.
Here, I think we're talking about two values at the same scope, and the overlap is a Venn diagram: Some implicit lower bounds are type-variable uses, and some type-variable uses are implicit lower bounds. (In my case, by contrast, "every
UNBOUNDED_WILDCARD_UPPER_BOUND
was anOTHERWISE
," so to speak.)I say all that because a possible solution to my problem was to give priority to defaults from smaller scopes. Here, though, that wouldn't help, assuming that I've understood correctly.
On this PR more generally:
I would have guessed that there were two separate defaulting steps: one for the lower bound of
E
and one for the use ofE
itself. And my thinking is that minusNull is right for the lower bound but that unspecified is right for the use. Is the problem that, once the defaulting system defaults the lower bound, it decides not to default the use ofE
itself? Does the entire idea of defaulting those two things separately indicate that I'm working from a different mental model than the Checker Framework does?That's probably it? This may get back into how substitution works differently (currently!) in the Checker Framework and JSpecify: Once the Checker Framework has an annotation for the use of a type variable, I think it applies that annotation to both of the bounds there? In contrast, JSpecify would say that "
E
" has a lower bound of minusNull but that "this use ofE
" has unspecified nullness.(So, backing up to the eisop question for a moment: It's probably not worth trying to accommodate this case unless we decide that we want to keep the JSpecify behavior as it is—and maybe not even then.)
So this seems in line with the other hacks I've put in as part of forcing the weird JSpecify substitution behavior. It might result in slightly weird error messages by our standards (with
null*
instead ofnull
)—still only when errors are triggered by some separate, real problem—but that's exactly the kind of thing that we can live with. And it may go away as we revisit substitution.