Repository navigation
[java] Fix #7054: Capture wildcard components of intersection bounds - #7055
Conversation
|
Compared to main: (comment created at 2026-10-22 16:12:50+00:00 for c0cc7b6) |
adangel
left a comment
There was a problem hiding this comment.
Thanks for the PR!
I've updated it to have the regression tester run again (because last time it reported many removed violations - but that's probably unrelated). I hope, I find more time later this week.
Method references never went through TypeOps#getMemberSource, so the IllegalArgumentException fixed by the previous commit was still reachable through `values::forEach`. There an intersection bound isn't even needed: capture() is the identity on a bare type variable too, so a receiver typed `C extends Iterable<?>` streamed the uncaptured upper bound, substituted `T := ?` into `forEach(Consumer<? super T>)` and tripped the check in TypeSystem#wildcard. Route both candidate-search sites in ExprOps through getMemberSource. In getAccessibleCandidates the capture happens only after the constructor-ref and raw second-search branches have been selected, so those paths, which need the declared type, are unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
adangel
left a comment
There was a problem hiding this comment.
Thanks!
For method refs, we had a similar problem. This is now also fixed.
Describe the PR
I think this fixes #7054. Calling
forEachthroughC extends Iterable<?> & Markercurrently throwsIllegalArgumentException: <?> cannot be a wildcard bound, even though the small reproducer compiles without warnings.TypeOps.getMemberSource captures a single parameterized upper bound, but an intersection reaches member lookup with its component wildcards uncaptured. This change follows type-variable upper bounds and captures each intersection component before resolving members.
The commits preserve the test-first sequence:
I'd appreciate a review of whether this is the right place to handle intersection member capture, especially any type-system cases the tests miss.
Related issues
Validation
On Corretto JDK 25.0.2 / macOS arm64:
The first command fails on the test-only commit and passes with the fix. The full Java reactor test run reports 16,701 tests, 31 skipped, zero failures/errors (16,670 passed), including the six new regression cases. Checkstyle reports zero violations. All six Java snippets also compile with
javac --release 17 -Xlint:all -Werror.The full distribution build across all languages has not been run locally.
Ready?
./mvnw clean verifypasses (checked automatically by GitHub Actions)