Repository navigation
Make a bound from a use that ignores annotations ignore annotations #8385
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
Open
mernst
wants to merge
264
commits into
typetools:master
Choose a base branch
from
mernst:ignored-use-of-variable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
264 commits
Select commit
Hold shift + click to select a range
42a3b51
Merge remote-tracking branch 'origin/master' into shallow-ignore-anno…
smillst 05549ef
Fold whether a ProperType has an origin into its hash code
smillst 1607687
Merge branch 'master' into shallow-ignore-annotations
smillst 550c8d6
Shorten and clarify Javadoc for ignored annotations in type inference
smillst 7b1aef2
Merge remote-tracking branch 'origin/master' into shallow-ignore-anno…
smillst 424e009
Merge branch 'master' into shallow-ignore-annotations
smillst 5480fa0
Merge branch 'master' into shallow-ignore-annotations
mernst 39144bc
Extract lubOfLowerBounds from Resolution.resolveWithLowerBounds
smillst c97794c
Merge branch 'lub-of-lower-bounds' of /home/mernst/research/types/che…
mernst 2dbfe56
Move the fix for bounds from uses that ignore annotations to a follow…
mernst 8fdb3a7
Make a bound from a use that ignores annotations ignore annotations
smillst 6b645e6
Retry type argument inference without the target type when only the t…
mernst 124bddc
Merge branch 'inference-retry-without-target' of github.com:mernst/ch…
mernst b250154
Remove expected type.arguments.not.inferred errors that are no longer…
mernst 9cf3ec2
Update warning suppressions for errors now reported after inference s…
mernst b85a5a2
Address code review: restructure retry, narrow suppression, skip futi…
mernst 1851ffd
Address code review: retry exceptions, construction inside try, targe…
mernst b2f9ddd
Merge branch 'master' into inference-retry-without-target
mernst 10c9459
Update expectations: retry now succeeds when the attempts create dist…
mernst 4164801
Assert non-null map lookups for the Nullness Checker
mernst d51d99e
De-duplicate: reuse TypesUtils.isSameTypeModuloCaptures, let retry cr…
mernst da0aba9
Merge branch 'master' into shallow-ignore-annotations
mernst 3a9d263
Merge branch 'master' into inference-retry-without-target
mernst e56dc6a
Merge branch 'inference-retry-without-target' into shallow-ignore-ann…
mernst efc1056
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 520abf8
Merge branch 'master' into inference-retry-without-target
mernst ed6d768
Merge branch 'inference-retry-without-target' into shallow-ignore-ann…
mernst a3ef412
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 157d2fc
Merge branch 'master' into inference-retry-without-target
mernst 3e6fa79
Merge branch 'inference-retry-without-target' into shallow-ignore-ann…
mernst 0450c40
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 4c5a7cb
Remove the changes of #8388, which will land after this pull request
mernst 8de0a39
Merge remote-tracking branch 'origin/master' into shallow-ignore-anno…
mernst 220d76e
Expect type.arguments.not.inferred that #8388 will turn into an assig…
mernst c0463c5
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 1c3a1b5
Merge remote-tracking branch 'upstream/master' into shallow-ignore-an…
mernst 6dd5e9d
Cache the origin's variables, check for false after resolving ignored…
mernst 61665a0
Merge remote-tracking branch 'pr/8305' into ignored-use-of-variable
mernst 4d0f3bf
Compare origins in ProperType.equals; keep origins in glb; refresh st…
mernst 4a5198d
Merge remote-tracking branch 'pr/8305' into ignored-use-of-variable
mernst a242c44
Merge branch 'master' into shallow-ignore-annotations
mernst 1bc1420
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 71ea983
Merge branch 'master' into shallow-ignore-annotations
mernst 1871297
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 8ffed05
Use "primary annotations" rather than "root annotations" in type argu…
smillst 731e90e
Rename `ProperType.originStamp` to `upToDateStamp`
smillst 05fe51a
Clarify that "them" refers to instantiations in `ProperType` origin d…
smillst d757079
Shorten the Javadoc of `ProperType.origin` to say what the field records
smillst f3fc0b0
Explain what `ProperType.qualifierVars` maps and how it is used
smillst 35a17f7
Say that a variable's instantiation is its current one, which can cha…
smillst 44633b8
Rename `ProperType.validatePartCaches` to `clearPartCachesIfStale`
smillst 958fa5f
Give `asSuper` its own cache in `ProperType` and document the part ca…
smillst 04d1c0b
Rename `partsFromOrigin` to `listPartFromOrigin` and say it computes …
smillst 565b351
Explain how `ProperType.isSameAnnotatedType` differs from `equals`
smillst 5e2e325
Merge remote-tracking branch 'origin/master' into shallow-ignore-anno…
smillst 76baf1d
List what `ProperType.copy` and `withAnnotatedType` keep as bullet po…
smillst 8a8f3a3
Clarify what `applyInstantiations` does
smillst e02465c
Call instantiation stamps "versions" and document why `instantiationC…
smillst 4c4c8d2
Explain why the instantiation is among the bounds in `applyInstantiat…
smillst 84a22ce
Say which instantiation "one" refers to in `applyInstantiationsToBounds`
smillst 19a3bea
Rename `requested` to `originalAs` in `Resolution.resolve`
smillst 2229f3a
Rename `includesEqualBounds` to `replaceIgnoredAnnotations` in `lubOf…
smillst 7dba166
Say what substitutes an ignored substitution, and that it is substitu…
smillst e20ffed
Explain how `IgnoredAnnotations` makes ignored annotations not affect…
smillst 901e7f5
Drop "in that order" from the `IgnoredAnnotations.replaceIgnored*` Ja…
smillst 0aae83e
Say directly what `replaceIgnoredForCombining` replaces
smillst 5892526
Rename `replaceIgnoredForCombining` to `replaceIgnoredForLubOrGlb`
smillst 19eedc0
Rename `IgnoredAnnotations.current` to `upToDate` and say whose insta…
smillst 965e7ef
Rename `alignedToClass` to `viewedAsClass` and explain what the view is
smillst b2c2745
Rename `decidedByIgnoredPrimaryAnnotations` to `noAnnotationsToCompare`
smillst 4faae75
Rename `hasOnlyPrimaryAnnotations` to `hasNoTypeArguments`; define "p…
smillst 1b53b4e
Declare `getOrigin` in `AbstractType` and remove `IgnoredAnnotations.…
smillst b16b0a2
Rename `atm` to `substituted` in `collectIgnoredSubstitutions` and `c…
smillst 2769f43
Rename `nonPolymorphicCount` to `nonPolymorphicPrimaryAnnotationCount`
smillst 9c7af8a
Say what `replaceIgnoredSubstitutions` does when both positions are i…
smillst da4766d
Clarify `boundOf` Javadoc and call `getSuperBound` once
smillst 9db9440
Replace ignored substitutions nested inside another ignored substitution
smillst 5ce1419
Keep an origin when substituting while a variable is unresolved
smillst cf2784e
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 84d4e5c
Bound the key type of ProperType.cached by Object
smillst e49915c
Merge branch 'master' into shallow-ignore-annotations
smillst 0818a8d
Keep a lub or glb origin only if its ignored substitutions stay ignored
smillst 207a4ed
Resolve ignored annotations of all dependencies in Resolution.resolve…
smillst dea55cc
Merge remote-tracking branch 'upstream/master' into shallow-ignore-an…
mernst 3139f78
Keep the record of ignored substitutions in the running lub
smillst 940b342
Don't add a fallback bound whose Java type differs from the instantia…
smillst d68545d
Resolve ignored annotations of dependencies on the early returns of r…
smillst 3304c68
Add a test and TODO for capture conversion losing ignored substitutions
smillst 33ece2b
Merge branch 'master' into shallow-ignore-annotations
smillst ef29003
Merge remote-tracking branch 'upstream/master' into shallow-ignore-an…
mernst 10486e5
Merge remote-tracking branch 'origin/master' into shallow-ignore-anno…
mernst 70b8b5d
Merge branch 'master' into shallow-ignore-annotations
mernst ad0ab55
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst dfe8e64
Document that resolveWithCapture omits bounds with deferred substitut…
mernst 904e6cf
Add tests of ignored substitutions in lubs, wildcards, capture, and c…
mernst e17b829
Document why the lub keeps only one origin
mernst 0810ca5
Don't keep the origin of a lub input whose ignored substitutions were…
mernst 081572d
Merge remote-tracking branch 'upstream/master' into shallow-ignore-an…
mernst cba7c1e
Documentation edits
mernst ea6d60b
Handle intersection types when matching corresponding positions; Java…
mernst 59099c1
Factor out mutual-subtype test; correct ReplacedTypes Javadoc
mernst 615a9c6
Revert "Don't keep the origin of a lub input whose ignored substituti…
smillst 66d89ec
Replace an instantiation that differs only in whether it ignores anno…
smillst 1605361
Clarify the IgnoredAnnotations class Javadoc and call formulas constr…
smillst 8c548c7
Clarify the ignoredSubstitutions Javadoc
smillst dbdc68f
Name the two ways of computing a part of a ProperType by their sources
smillst 97d356b
Clarify the checkAnnotationEquality Javadoc
smillst 958caf2
Call a position whose annotations are ignored an ignored position
smillst cf8b45c
Clarify how replaceIgnoredForSubtype replaces ignored annotations
smillst 939cf16
Rename viewedAsClass to asSuper and the aligned locals to match
smillst f8535fb
Say when replaceIgnoredForLubOrGlb replaces nothing
smillst 5f918de
Say what "them" refers to in the noAnnotationsToCompare Javadoc
smillst 8baf7bc
Clarify the ignoreAnnotations and checkAnnotationSubtype Javadoc
smillst 85db9b8
Clarify parts of a ProperType and rename sharesPrimaryAnnotations
smillst a66cb21
Say that UseOfVariable adds bounds to the variable it is a use of
smillst 6b3416d
Clarify which annotations of an EQUAL bound are ignored in VariableBo…
smillst 20c20aa
Rename Resolution.viewAs to asSupertype and clarify resolveIgnoredAnn…
smillst 887d949
Merge remote-tracking branch 'origin/master' into shallow-ignore-anno…
smillst ed73e88
Merge branch 'master' into shallow-ignore-annotations
mernst b55f522
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 7987fa2
Remove redundant ignoreAnnotations comparison in setInstantiation
mernst f158603
Revert "Replace an instantiation that differs only in whether it igno…
smillst 56a737d
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 8b1b41a
Document the limitation of keeping the origin of only one lub input
mernst e415428
Do not ignore qualifier lower bounds that replace ignored annotations
mernst 5bd8e37
Clarify instantiationChanges and the early return in setInstantiation
mernst 5675cb7
Merge branch 'shallow-ignore-annotations' of ../checker-framework-for…
mernst b0011ff
Rewrap a TODO comment in resolveWithCapture
mernst 1a55ac3
Merge ../checker-framework-fork-smillst-branch-shallow-ignore-annotat…
mernst 1d28e7a
Merge branch 'master' into shallow-ignore-annotations
mernst 74588c6
Compare the upper bound of a type variable when deciding whether igno…
mernst 4d7b6f9
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst d2e1c73
Code review edits
mernst e606472
Clarify comments about ignored primary annotations
smillst a4af84f
Code review edits
smillst a3a2949
Merge remote-tracking branch 'origin/master' into shallow-ignore-anno…
smillst 92e752b
Say that withOriginOf usually returns null
smillst 489cf9d
Don't use Map.computeIfAbsent with a function that may return null
smillst 1dda15a
Test a call whose result is a lambda's return expression
smillst 2359c94
Guard ignored-position walkers against cyclic wildcards; do not propa…
mernst 6fe4060
Merge remote-tracking branch 'upstream/master' into shallow-ignore-an…
mernst 2234326
Put the public API first in the file
mernst 9c84282
Doc edits
mernst 669bddd
Doc edits
mernst b618ef0
Avoid a dangling documentation comment
mernst 9daca94
Guard ignored-position walkers against cyclic wildcards
mernst 999fd11
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst afd48bf
Remove test RawRecursiveBoundOfIgnoredPosition, which passes without …
mernst 5db7ace
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 172bfbe
Compare enclosing-type annotations when checking whether an instantia…
mernst 99bef83
Define a position as a location, and refer to the class definition of…
smillst 26855ca
Say which annotation wins when a position is ignored in both types; f…
smillst f7de82e
List the steps of replaceIgnoredForLubOrGlb in the order they occur
smillst e22b05f
Say that ignoredPositionsStayIgnored is not commutative
smillst 1b7c88e
Say which check noAnnotationsToCompare is about and why it cannot fail
smillst a62c324
Define current instantiation, and say when upToDate returns its argument
smillst 363c7e7
Name the asSuper parameter superType, as in AbstractType.asSuper
smillst 7b80ebd
Move samePrimaryAnnotationsAtEveryPosition above the private-methods …
mernst 0640b99
Rename hasNoTypeArguments to onlyPrimaryAnnotationsAreCompared, which…
smillst dc17a14
Say "contains" rather than "mentions", and say which instantiations c…
smillst 17d4b42
Make a length mismatch in collectPairwise a bug, and say why one is n…
smillst 56a7d38
Merge github.com:typetools/checker-framework into shallow-ignore-anno…
mernst 96c4438
Say which positions a wildcard corresponds to in allCorrespondingPosi…
smillst 00c2054
Rename allCorrespondingPositions to allCorrespondingPositionsMatch, t…
smillst e8e90f7
Align ignored positions with a type variable's upper bound in replace…
smillst b9a8dea
Add a TODO about out-of-date transitive origin dependencies
smillst 13e9209
Keep an upper bound that contains an instantiated variable when resol…
smillst 7e53933
Merge remote-tracking branch 'smillst/shallow-ignore-annotations' int…
smillst ad704dc
Merge branch 'master' into shallow-ignore-annotations
mernst a896526
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst 095ce8b
Fix the build after merging branch 'shallow-ignore-annotations'
mernst 385f1da
Address review comments on ignored annotations
mernst 4213496
Test whether a type is a type variable rather than comparing it to it…
smillst 6ef019a
Substitute copies of instantiations in getSubsTypeArgs
smillst fc9944c
Incorporate after resolving ignored annotations if the instantiation …
smillst 260f067
Don't pair the type arguments of declared types of different classes
smillst aa4be55
Replace ignored annotations by qualifier lower bounds when resolving …
smillst 5c4e87c
Revert "Replace ignored annotations by qualifier lower bounds when re…
smillst e171884
Rename `ai` to `variable` in Resolution
smillst 41594b3
Name the origin and say which annotations are ignored in the comments…
smillst 8e53f87
Say why getOrCompute does not use Map.computeIfAbsent
smillst 1052084
Simplify IgnoredAnnotations documentation; rename replaceIgnoredPosit…
smillst 4da9c69
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst c4d9aa9
Merge remote-tracking branch 'upstream/master' into shallow-ignore-an…
mernst b3c4911
In resolveWithCapture, substitute instantiations of skipped variables…
mernst 274fa51
Pass every instantiated variable in an upper bound to getSubsTypeArgs…
mernst cd1983d
Merge branch 'shallow-ignore-annotations' into ignored-use-of-variable
mernst aaf8058
Merge branch 'shallow-ignore-annotations' into ignored-annotations-co…
mernst 1c54ac8
Correct the handling of ignored annotations in type argument inference
mernst b1435b0
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst 4cc269d
Document the lub of positions that both types ignore; reflow a test c…
mernst 91a952a
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst 1390c44
Move all but the per-hierarchy corrections to later pull requests
mernst 074f83a
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst b9f3096
Compare enclosing types when deciding whether types with origins are …
mernst ee54808
Merge branch 'master' into shallow-ignore-annotations
mernst 21a0017
Merge branch 'shallow-ignore-annotations' into ignored-annotations-co…
mernst 980e168
Reformat
mernst 0e63763
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst c8348a9
Address review comments on ignored annotations
mernst 81a7315
Address review comments: use-site qualifiers in capture bounds, inter…
mernst 1a10f26
Merge branch 'master' into shallow-ignore-annotations
mernst 171418a
Merge branch 'shallow-ignore-annotations' into ignored-annotations-co…
mernst 186d4f8
Reformat
mernst b1a8476
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst 5dd2144
Recheck bounds whose enclosing types change; track visited wildcard p…
mernst 030d84f
Merge branch 'master' into shallow-ignore-annotations
mernst 4432b33
Merge branch 'shallow-ignore-annotations' into ignored-annotations-co…
mernst 2b72f17
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst 9d1e0eb
Align array components for ignored annotations; decompose up-to-date …
mernst a814cf8
Repair ignored instantiations using real qualifier lower bounds; dete…
mernst b1bfa7d
Merge branch 'master' into shallow-ignore-annotations
mernst 368e17b
Merge branch 'shallow-ignore-annotations' into ignored-annotations-co…
mernst 91c8c26
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst cbf8f8c
Address review: invariant array components, up-to-date lub/glb inputs…
mernst 1de7a65
Reformat
mernst a5f6fca
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst e2c9c6d
Merge branch 'master' into shallow-ignore-annotations
mernst 473f612
Merge branch 'shallow-ignore-annotations' into ignored-annotations-co…
mernst b604fc2
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst 2972962
Set an instantiation only from an equal bound that the bound set accepts
mernst a683185
Compare a type variable's upper bound with an ignored position; fix a…
mernst 3ba0d39
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst 0a73aa8
Do not recheck refreshed bounds against their complementary bounds
mernst 48ec1ce
Lub the qualifier lower bounds into an ignored lub rather than replac…
mernst dd2c1f1
Do not align the components of arrays of different classes
mernst 37e9c5c
Copy a wildcard's or intersection's bound primary annotations only in…
mernst c91fec0
Track visited wildcard pairs, not only wildcards, when comparing encl…
mernst dff1697
Copy ignored primary annotations in a hierarchy with a class qualifie…
mernst 12424f2
Merge remote-tracking branch 'origin/ignored-annotations-corrections'…
mernst 2a22d9a
Factor a binary lub out of InferenceFactory#lub(Set)
smillst d4806a2
Clarify InferenceFactory#withOriginOf; inline its helper
smillst c335f9a
Distinguish ignoring annotations from having an origin; rename findLo…
smillst cff1821
Document when a ProperType is reapplied from its origin; drop a misle…
smillst ae5fe68
Clarify that a caller must not mutate either element of a ReplacedTypes
smillst 45ab541
Compare enclosing types when deciding whether a type with an origin i…
smillst 974a063
Apply the annotations on a use when substituting an instantiation int…
smillst d6426c0
Resolve the ignored annotations of variables in dependency order
smillst 26d9bcc
Pair ignored positions with those of an array component or a type var…
smillst d4e5472
Do not say that a position is "no longer ignored"
smillst 2f31580
Merge branch 'master' into shallow-ignore-annotations
mernst 4eebc49
Merge branch 'shallow-ignore-annotations' into ignored-annotations-co…
mernst d565c64
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst 4dd6e29
Clarify the documentation of getSubsTypeArgs and of capture in resolv…
mernst 4334eab
Merge branch 'ignored-annotations-corrections' of github.com:mernst/c…
mernst 8371581
Merge branch 'master' into shallow-ignore-annotations
mernst b2c44d6
Merge branch 'shallow-ignore-annotations' into ignored-annotations-co…
mernst af38f5c
Merge branch 'ignored-annotations-corrections' into ignored-use-of-va…
mernst 08db99d
Pair ignored positions through an intersection upper bound; remove un…
mernst 5ddf46b
Merge remote-tracking branch 'origin/ignored-annotations-corrections'…
mernst 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
55 changes: 55 additions & 0 deletions
55
checker/tests/nullness/AnnotatedWildcardOfIgnoredPosition.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,55 @@ | ||
| import java.util.List; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| // A wildcard with a primary annotation whose bound is an ignored position. B = U comes from a use | ||
| // with an explicit annotation, so it ignores annotations, and the bound of the wildcard in the | ||
| // result of nnList or nbleList is an ignored position. B's annotations come from `other`. | ||
| public class AnnotatedWildcardOfIgnoredPosition { | ||
| static class Box<T> {} | ||
|
|
||
| static <B extends @Nullable Object> List<@NonNull ? extends B> nnList( | ||
| Box<@NonNull B> b, B other) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <B extends @Nullable Object> List<@Nullable ? extends B> nbleList( | ||
| Box<@NonNull B> b, B other) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <S extends @Nullable Object> S id(S s) { | ||
| return s; | ||
| } | ||
|
|
||
| static <S extends @Nullable Object> S pick2(S a, S b) { | ||
| return a; | ||
| } | ||
|
|
||
| static <U extends @Nullable Object> void test( | ||
| Box<@NonNull U> nonNullU, | ||
| @NonNull U nn, | ||
| @Nullable U nble, | ||
| List<? extends @Nullable U> nullableList, | ||
| List<? extends @NonNull U> nonNullList) { | ||
| // :: error: (dereference.of.nullable) | ||
| id(nnList(nonNullU, nble)).get(0).toString(); | ||
| // TODO: This is a false positive. B is @NonNull U, so the upper bound of the wildcard is too. | ||
| // :: error: (dereference.of.nullable) | ||
| id(nnList(nonNullU, nn)).get(0).toString(); | ||
| // :: error: (argument) | ||
| List<? extends @NonNull U> a1 = id(nnList(nonNullU, nble)); | ||
| List<? extends @Nullable U> a2 = id(nnList(nonNullU, nble)); | ||
| // :: error: (dereference.of.nullable) | ||
| id(nbleList(nonNullU, nn)).get(0).toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| pick2(nnList(nonNullU, nn), nullableList).get(0).toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| pick2(nnList(nonNullU, nble), nonNullList).get(0).toString(); | ||
| // TODO: This is a false positive. See the call of id above. | ||
| // :: error: (dereference.of.nullable) | ||
| pick2(nnList(nonNullU, nn), nonNullList).get(0).toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| pick2(nbleList(nonNullU, nn), nonNullList).get(0).toString(); | ||
| } | ||
| } |
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,38 @@ | ||
| import java.util.List; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| // Capture conversion of a type with an ignored position in the bound of a wildcard. B = U comes | ||
| // from a use with an explicit annotation, so it ignores annotations, and the bound of the wildcard | ||
| // in the result of listOf or listOfN is an ignored position. | ||
| public class CaptureOfIgnoredPosition { | ||
| static class Box<T> {} | ||
|
|
||
| static <B extends @Nullable Object> List<? extends B> listOf(Box<@NonNull B> b, B other) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <B extends @Nullable Object> List<? extends B> listOfN(Box<@Nullable B> b, B other) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <E extends @Nullable Object> E get0(List<? extends E> l) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <U extends @Nullable Object> void test( | ||
| Box<@NonNull U> nonNullU, Box<@Nullable U> nullableU, @NonNull U nn, @Nullable U nble) { | ||
| // :: error: (dereference.of.nullable) | ||
| get0(listOf(nonNullU, nble)).toString(); | ||
| // TODO: This is a false positive. Capture conversion of the argument's type makes the ignored | ||
| // position the upper bound of a captured type variable, and the result of capture conversion | ||
| // (see ProperType#create) does not record ignored positions, so the ignored annotation, | ||
| // @Nullable, is compared as a real annotation. | ||
| // :: error: (dereference.of.nullable) | ||
| get0(listOfN(nullableU, nn)).toString(); | ||
|
|
||
| // :: error: (dereference.of.nullable) | ||
| listOf(nonNullU, nble).get(0).toString(); | ||
| listOfN(nullableU, nn).get(0).toString(); | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
checker/tests/nullness/CaptureOfIgnoredPositionWithUnresolvedVariable.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,37 @@ | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| // T's instantiation ignores annotations, because its EQUAL bound comes from a use with an explicit | ||
| // annotation. Applying T's instantiation to Map<T, R> is deferred while R is still unresolved. | ||
| // wl's result is wildcard-parameterized, so inferring a call that has it as an argument or as its | ||
| // target uses capture variables. | ||
| public class CaptureOfIgnoredPositionWithUnresolvedVariable { | ||
| static class Box<T> {} | ||
|
|
||
| static <S extends @Nullable Object> S id(S s) { | ||
| return s; | ||
| } | ||
|
|
||
| static <S extends @Nullable Object> List<? extends S> wl(S s) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <T extends @Nullable Object, R extends @Nullable Object> Map<T, R> mk( | ||
| Box<@NonNull T> b, T other, R r) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <U extends @Nullable Object> void test(Box<@NonNull U> nonNullU, @Nullable U nble) { | ||
| wl(mk(nonNullU, nble, "x")); | ||
| // TODO: This is a false positive. | ||
| // :: error: (argument) | ||
| id(wl(mk(nonNullU, nble, "x"))); | ||
| List<? extends Map<@Nullable U, String>> l1 = wl(mk(nonNullU, nble, "x")); | ||
| List<? extends Map<@Nullable U, String>> l2 = id(wl(mk(nonNullU, nble, "x"))); | ||
| // TODO: This is a false positive. | ||
| // :: error: (argument) | ||
| id(wl(mk(nonNullU, nble, "x"))).get(0).toString(); | ||
| } | ||
| } |
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,30 @@ | ||
| import java.util.List; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
| import org.checkerframework.checker.nullness.util.NullnessUtil; | ||
|
|
||
| // castNonNull's parameter and result are uses of T with explicit primary annotations, so T's bounds | ||
| // from the argument and from the assignment context ignore primary annotations, but not nested | ||
| // ones. If the nested annotations of the argument and of the assignment context conflict, then | ||
| // inference fails as well as the assignment. | ||
| public class CastNonNullNestedAnnotations { | ||
| void arrays( | ||
| @Nullable Object @Nullable [] nullableElts, @NonNull Object @Nullable [] nonNullElts) { | ||
| @Nullable Object[] a1 = NullnessUtil.castNonNull(nullableElts); | ||
| @NonNull Object[] a2 = NullnessUtil.castNonNull(nonNullElts); | ||
| @Nullable Object[] a3 = NullnessUtil.castNonNull(nonNullElts); | ||
| // :: error: (assignment) :: error: (type.arguments.not.inferred) | ||
| @NonNull Object[] a4 = NullnessUtil.castNonNull(nullableElts); | ||
| // :: error: (dereference.of.nullable) | ||
| NullnessUtil.castNonNull(nullableElts)[0].toString(); | ||
| } | ||
|
|
||
| void lists(@Nullable List<@Nullable String> nullableElts, @Nullable List<String> nonNullElts) { | ||
| List<@Nullable String> l1 = NullnessUtil.castNonNull(nullableElts); | ||
| List<String> l2 = NullnessUtil.castNonNull(nonNullElts); | ||
| // :: error: (assignment) :: error: (type.arguments.not.inferred) | ||
| List<String> l3 = NullnessUtil.castNonNull(nullableElts); | ||
| // :: error: (dereference.of.nullable) | ||
| NullnessUtil.castNonNull(nullableElts).get(0).toString(); | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
checker/tests/nullness/EnclosingTypeOfIgnoredPosition.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,55 @@ | ||
| // Inferred inner class types whose enclosing types contain ignored positions. | ||
|
|
||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| public class EnclosingTypeOfIgnoredPosition { | ||
| static class Box<T extends @Nullable Object> {} | ||
|
|
||
| static class Outer<A extends @Nullable Object> { | ||
| class Inner<B extends @Nullable Object> { | ||
| A getA() { | ||
| throw new RuntimeException(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static <B extends @Nullable Object> Outer<@NonNull String>.Inner<B> nnOuter(Box<@NonNull B> b) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <B extends @Nullable Object> Outer<@Nullable String>.Inner<B> nbleOuter( | ||
| Box<@NonNull B> b) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| // The instantiation of A becomes @Nullable U because of `other`; that of B stays @NonNull U. | ||
| static <A extends @Nullable Object, B extends @Nullable Object> Outer<A>.Inner<B> both( | ||
| Box<@NonNull A> a, A other, Box<@NonNull B> b) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <S extends @Nullable Object> S pick2(S a, S b) { | ||
| return a; | ||
| } | ||
|
|
||
| static <S extends @Nullable Object> S id(S s) { | ||
| return s; | ||
| } | ||
|
|
||
| static <U extends @Nullable Object> void test( | ||
| Box<@NonNull String> nnString, Box<@NonNull U> nonNullU, @Nullable U nble) { | ||
| // :: error: (dereference.of.nullable) | ||
| pick2(nnOuter(nnString), nbleOuter(nnString)).getA().length(); | ||
| // :: error: (dereference.of.nullable) | ||
| pick2(nbleOuter(nnString), nnOuter(nnString)).getA().length(); | ||
| // :: error: (dereference.of.nullable) | ||
| both(nonNullU, nble, nonNullU).getA().toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| id(both(nonNullU, nble, nonNullU)).getA().toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| id(id(both(nonNullU, nble, nonNullU))).getA().toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| pick2(both(nonNullU, nble, nonNullU), both(nonNullU, nble, nonNullU)).getA().toString(); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
checker/tests/nullness/IgnoredInstantiationResolutionOrder.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,26 @@ | ||
| // A's lower bounds are B[] and @NonNull U[]. B's instantiation ignores annotations, and it becomes | ||
| // @Nullable U because of `other`. A's instantiation must use B's final instantiation, whichever | ||
| // of A and B is resolved first. | ||
|
|
||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| public class IgnoredInstantiationResolutionOrder { | ||
| static class Box<T extends @Nullable Object> {} | ||
|
|
||
| static <B extends @Nullable Object> B[] arrOf(Box<@NonNull B> b, B other) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <A extends @Nullable Object> A pickA(@NonNull A x, @NonNull A y) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <U extends @Nullable Object> void test( | ||
| Box<@NonNull U> nonNullU, @Nullable U nble, @NonNull U[] nonNullArr) { | ||
| // :: error: (dereference.of.nullable) | ||
| pickA(arrOf(nonNullU, nble), nonNullArr)[0].toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| pickA(nonNullArr, arrOf(nonNullU, nble))[0].toString(); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
checker/tests/nullness/IgnoredInstantiationWithUnrelatedLowerBounds.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,43 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| // T = X comes from a use with an explicit annotation, so it ignores annotations, and resolution | ||
| // takes T's annotations from its lower bounds. The least upper bound of those lower bounds is not | ||
| // the instantiation's Java type X: it is a different parameterization of X, a subtype of X, or a | ||
| // raw type. | ||
| public class IgnoredInstantiationWithUnrelatedLowerBounds { | ||
| static class Box<T> {} | ||
|
|
||
| static <T extends @Nullable Object> T pick(Box<@NonNull T> b, T x, T y) { | ||
| return x; | ||
| } | ||
|
|
||
| static void wildcards( | ||
| Box<@NonNull List<? extends Object>> bWild, | ||
| Box<@NonNull List<?>> bUnbounded, | ||
| @Nullable List<String> nls, | ||
| List<Integer> li) { | ||
| // :: error: (dereference.of.nullable) | ||
| pick(bWild, nls, li).toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| pick(bUnbounded, nls, li).toString(); | ||
| // :: error: (dereference.of.nullable) | ||
| pick(bWild, li, nls).toString(); | ||
| } | ||
|
|
||
| @SuppressWarnings("rawtypes") | ||
| static void raw( | ||
| Box<@NonNull List> bRaw, @Nullable ArrayList<String> nal, LinkedList<Integer> ll) { | ||
| // :: error: (dereference.of.nullable) | ||
| pick(bRaw, nal, ll).toString(); | ||
| } | ||
|
|
||
| static void classes( | ||
| Box<@NonNull Object> bObj, @Nullable ArrayList<String> nal, LinkedList<Integer> ll) { | ||
| // :: error: (dereference.of.nullable) | ||
| pick(bObj, nal, ll).toString(); | ||
| } | ||
| } |
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,45 @@ | ||
| // A's instantiation ignores annotations, because its EQUAL bound comes from a use with an explicit | ||
| // annotation; it gets its annotations from `other`. The ignored positions are compared with the | ||
| // positions of a subtype of another class: the component type of an array, or the upper bound of | ||
| // a type variable. | ||
|
|
||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| public class IgnoredPositionOfSuperclass { | ||
| static class Box<T extends @Nullable Object> {} | ||
|
|
||
| static class Parent<X extends @Nullable Object> {} | ||
|
|
||
| static class Child<X extends @Nullable Object> extends Parent<X> {} | ||
|
|
||
| static <A extends @Nullable Object> Child<A>[] mkArr(Box<@NonNull A> b, A other) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <A extends @Nullable Object> Child<A> mk(Box<@NonNull A> b, A other) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <S extends @Nullable Object> S id(S s) { | ||
| return s; | ||
| } | ||
|
|
||
| static <A extends @Nullable Object, S extends Parent<A>> void take( | ||
| Box<@NonNull A> b, A other, S s) {} | ||
|
|
||
| static <U extends @Nullable Object> void arrays(Box<@NonNull U> nonNullU, @Nullable U nble) { | ||
| Parent<@Nullable U>[] r1 = id(mkArr(nonNullU, nble)); | ||
| // :: error: (assignment) | ||
| Parent<@NonNull U>[] r2 = id(mkArr(nonNullU, nble)); | ||
| Parent<@Nullable U> r3 = id(mk(nonNullU, nble)); | ||
| } | ||
|
|
||
| static <U extends @Nullable Object, V extends Child<@Nullable U>> void typeVariables( | ||
| Box<@NonNull U> nonNullU, @Nullable U nble, @NonNull U nn, V v, Child<@Nullable U> c) { | ||
| take(nonNullU, nble, v); | ||
| // :: error: (type.argument) | ||
| take(nonNullU, nn, v); | ||
| take(nonNullU, nble, c); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
checker/tests/nullness/IgnoredPositionWithUnresolvedVariable.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,26 @@ | ||
| import java.util.Map; | ||
| import org.checkerframework.checker.nullness.qual.NonNull; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| // T's instantiation ignores annotations, because its EQUAL bound comes from a use with an explicit | ||
| // annotation, and it is applied to S's lower bound Map<T, R> while R is still unresolved. | ||
| public class IgnoredPositionWithUnresolvedVariable { | ||
| static class Box<T> {} | ||
|
|
||
| static <S extends @Nullable Object> S id(S s) { | ||
| return s; | ||
| } | ||
|
|
||
| static <T extends @Nullable Object, R extends @Nullable Object> Map<T, R> mk( | ||
| Box<@NonNull T> b, T other, R r) { | ||
| throw new RuntimeException(); | ||
| } | ||
|
|
||
| static <U extends @Nullable Object> void test(Box<@NonNull U> nonNullU, @Nullable U nble) { | ||
| id(mk(nonNullU, nble, "x")); | ||
| Map<@Nullable U, String> m1 = id(mk(nonNullU, nble, "x")); | ||
| Map<@Nullable U, String> m2 = mk(nonNullU, nble, "x"); | ||
| Map<@Nullable U, @Nullable String> m3 = id(mk(nonNullU, nble, null)); | ||
| Map<@Nullable U, String> m4 = id(id(mk(nonNullU, nble, "x"))); | ||
| } | ||
| } |
Oops, something went wrong.
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 test locks in a known false positive.
The TODO says the
dereference.of.nullableerror on line 32 is spurious. The expected-error marker makes the test pass only while this wrong behavior stays. When the capture gap is fixed, the test fails and needs an update. A@SuppressWarningsor a separate tracking issue with the same marker makes the intent easier to find. Keep the marker if the project accepts pinned false positives, and link an issue number in the TODO.