Repository navigation
Improved inference for generic method calls #1244
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
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
bfed991
WIP
msridhar 0f0d3ab
Merge branch 'master' into generics-type-constraint-solver
msridhar 6a889ce
test case
msridhar 5982410
WIP
msridhar 9d7ac36
WIP
msridhar 320d900
more
msridhar 3d4ee01
WIP
msridhar 3dfbd32
WIP
msridhar 5e3ae6f
WIP
msridhar a2b1c38
WIP
msridhar 6379b3b
WIP
msridhar 3450cda
WIP
msridhar 3a81eea
WIP
msridhar 1009394
WIP
msridhar 3a1d716
something works
msridhar 4d3d9c3
delete unused parameter
msridhar 42ba7bd
cleanup
msridhar 143a1c8
tweak
msridhar bd77f67
WIP
msridhar cb4da30
tweaks
msridhar e456d54
Merge branch 'master' into generics-type-constraint-solver
msridhar 787d74d
WIP
msridhar 97503b2
WIP
msridhar 8737d42
WIP
msridhar 4a866f3
more
msridhar 6c8042c
tweak
msridhar fa95c5c
more
msridhar 323bf1e
Merge branch 'master' into generics-type-constraint-solver
msridhar d9b9f75
Merge branch 'master' into generics-type-constraint-solver
msridhar dcf9137
fix
msridhar a889427
Merge branch 'master' into generics-type-constraint-solver
msridhar 5d16362
more fixes!
msridhar 6749ecc
fix another test
msridhar 480c339
WIP
msridhar 90b6943
tests passing!
msridhar 8434042
small optimization
msridhar 0fd9239
more tests
msridhar 1f119a1
avoid indirection through superclass
msridhar bd0ec0f
fix a couple things
msridhar a3ac99d
remove print
msridhar 9922483
failing test
msridhar fe944c6
fix varargs bug
msridhar dcf95fc
another test
msridhar d1bbf28
tweak test
msridhar 2862630
fix another bug
msridhar 7db7443
cleanup
msridhar eb0c315
more cleanup
msridhar c023481
improve javadoc and rename exception type
msridhar 3902921
remove dead code
msridhar 304776f
improve test coverage
msridhar 914bbba
javadoc on field
msridhar b34ef65
cleanup
msridhar 0b6103b
tweaks
msridhar 67c47a3
more
msridhar 6264812
add todo
msridhar f1bd090
more
msridhar cf49448
more
msridhar 45aad64
restore @Nullable annotation
msridhar fb97eb2
more tests
msridhar 0f6a460
ignore test
msridhar 825285b
Merge branch 'master' into generics-type-constraint-solver
msridhar 1059f40
Merge branch 'master' into generics-type-constraint-solver
msridhar 34dc49a
Merge branch 'master' into generics-type-constraint-solver
msridhar 1d30dc9
Merge branch 'master' into generics-type-constraint-solver
msridhar 04f7bff
fix covariant array subtyping
msridhar c9d7e08
remove useless statement
msridhar 893b22e
comment on why unchecked exception
msridhar 7ffb9da
delete bogus code and add comment
msridhar 44b0e75
update javadoc
msridhar 676b89c
improved comments
msridhar 8ad8e7b
clarify capture variables
msridhar ad36de8
WIP
msridhar 5147295
WIP
msridhar 417b1b1
WIP
msridhar d8069af
more
msridhar c0210d8
Merge branch 'more-instance-state-in-generics-checks' into generics-t…
msridhar 128a74f
cleanup
msridhar 7520d48
Merge branch 'master' into generics-type-constraint-solver
msridhar 4d710ae
Merge branch 'master' into generics-type-constraint-solver
msridhar ee2fdd6
More generics inference fixes (#1255)
msridhar 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
53 changes: 53 additions & 0 deletions
53
nullaway/src/main/java/com/uber/nullaway/generics/ConstraintSolver.java
This file contains hidden or 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,53 @@ | ||
| package com.uber.nullaway.generics; | ||
|
|
||
| import com.sun.tools.javac.code.Type; | ||
| import java.util.Map; | ||
| import javax.lang.model.element.Element; | ||
|
|
||
| /** | ||
| * An interface for solving constraints on type variables, such as subtype relationships between | ||
| * types. This is used to determine the nullability of inferred type arguments at generic method | ||
| * calls, constructor calls using the diamond operator, etc. | ||
| */ | ||
| public interface ConstraintSolver { | ||
|
|
||
| /** | ||
| * Exception thrown when the constraints added to the solver are determined to be unsatisfiable. | ||
| * | ||
| * <p>This is an unchecked exception since in our current solver implementation it needs to be | ||
| * thrown from an implementation of javac's TypeVisitor interface, which does not allow checked | ||
| * exceptions. | ||
| */ | ||
| class UnsatisfiableConstraintsException extends RuntimeException { | ||
| public UnsatisfiableConstraintsException(String message) { | ||
| super(message); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Add a subtype constraint between two types. Also constrains nested types appropriately (e.g., | ||
| * generic type parameters of the two types must have identical nullability). | ||
| * | ||
| * @param subtype the subtype | ||
| * @param supertype the supertype | ||
| * @param localVariableType whether this constraint arises from assigning to a local variable. In | ||
| * such a case, the top-level types are not constrained to be subtypes (as local variable | ||
| * types are separately inferred), but the nested types are still constrained. | ||
| * @throws UnsatisfiableConstraintsException if the constraints are determined to be unsatisfiable | ||
| */ | ||
| void addSubtypeConstraint(Type subtype, Type supertype, boolean localVariableType) | ||
| throws UnsatisfiableConstraintsException; | ||
|
|
||
| enum InferredNullability { | ||
| NONNULL, | ||
| NULLABLE | ||
| } | ||
|
|
||
| /** | ||
| * Solve the constraints, returning a map from type variables to their inferred nullability. | ||
| * | ||
| * @return a map from type variables to their inferred nullability | ||
| * @throws UnsatisfiableConstraintsException if the constraints are determined to be unsatisfiable | ||
| */ | ||
| Map<Element, InferredNullability> solve() throws UnsatisfiableConstraintsException; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.