Test capture glb with a non-top type-parameter bound#1876
Open
wmdietl wants to merge 2 commits into
Open
Conversation
framework/tests/h1h2checker/WildcardBounds.java notes it only exercises
wildcard capture against a top type-parameter bound ("We could add an
OuterS1 to also test with a non-top upper bound."), for which the glb of
the wildcard's extends bound and the parameter bound trivially equals the
wildcard's bound.
Add a nontopdefault test capturing Foo<? extends Bar> where
Foo<T extends @NTDTop Object> and the wildcard's extends bound (the
@NTDMiddle type-use default, or an explicit qualifier) is strictly more
precise than the @NTDTop parameter bound. This confirms the captured type
variable's upper bound is the greatest lower bound (@NTDMiddle), not the
parameter bound wholesale, and that the result varies with the wildcard's
extends bound (an explicit @NTDTop bound is not assignable to @NTDMiddle).
This is the CF-level reduction for cf-tasks/task-3; see
cf-tasks/task-3-findings.md. Capture conversion computes the glb
correctly in stock CF, so no framework change is warranted.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Investigation of the report that capture conversion drops a wildcard's more-precise qualifier from the capture's upper bound (observed through the JSpecify reference checker). Verdict: stock CF is correct — no framework change is warranted. This PR adds the test coverage that proves it.
Diagnosis
Instrumenting
annotateCapturedTypeVar(AnnotatedTypeFactory.java:6196) andTypeVariableSubstitutorshowed:annotateCapturedTypeVardoes computeannotatedGLB(typeVarUpperBound, wildcard.getExtendsBound()), and the per-hierarchy glb returns the correct, more-precise side (typeVarUB=@NTDTop Object,wildcardExtends=@NTDMiddle Bar→glbUB=@NTDMiddle Bar).NullSpecAnnotatedTypeFactory.substituteTypeVariableoverride: stock CF only overrides on the use's primary annotation (empty for a bareT), while the override additionally applies the bound's effective unspecified operator, clobbering the capture's precise qualifier. The sample failure pattern keys on the parameter's bound qualifier, consistent with substitution, not capture.Follow-up therefore belongs in the reference checker (skip the effective-annotation clause when the argument is a captured type variable with a more precise bound), not in CF.
This PR contains
framework/tests/nontopdefault/CaptureGlbWildcardBound.java— a passing regression test filling the gap explicitly noted inh1h2checker/WildcardBounds.java(wildcard capture against a non-top type-parameter bound, where the glb is not trivially the wildcard's bound). Includes a discriminating control:? extends @NTDTop Barmust not be assignable to@NTDMiddle, proving the glb varies with the wildcard's extends bound.(The
cf-tasks/task-3-findings.mdreferenced in the comments is the full diagnosis write-up in the local task workspace, not in this repo.)Tests:
:framework:test(including the new test) and:checker:NullnessTestpass.🤖 Generated with Claude Code
https://claude.ai/code/session_01EaHhVqLoJukm4kKsE7UfY4