Skip to content

Use adapted bounds for method/constructor type arguments - #1850

Merged
wmdietl merged 20 commits into
eisop:masterfrom
aosen-xiong:method-typevariables-from-use
Aug 5, 2026
Merged

Use adapted bounds for method/constructor type arguments#1850
wmdietl merged 20 commits into
eisop:masterfrom
aosen-xiong:method-typevariables-from-use

Conversation

@aosen-xiong

@aosen-xiong aosen-xiong commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Split from #1173.

Use viewpoint-adapted method type parameter bounds when checking method invocation type arguments.

Adds a viewpoint test covering explicit and inferred type arguments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Checker Framework’s method-invocation type argument checking to use viewpoint-adapted bounds for method type parameters, and adds a viewpoint test to exercise both explicit and inferred method type arguments against those adapted bounds.

Changes:

  • Add AnnotatedTypeFactory.methodTypeVariablesFromUse(...) to compute method type-parameter bounds in the invocation’s viewpoint.
  • Use the new adapted-bounds helper from BaseTypeVisitor.visitMethodInvocation(...) when validating method type arguments.
  • Add a new viewpoint test covering explicit and inferred method type arguments with receiver-dependent bounds.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
framework/tests/viewpointtest/MethodTypeVariableBounds.java New test cases for receiver-dependent method type parameter bounds under different receiver viewpoints.
framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java Introduces a helper to compute invocation-viewpoint-adapted method type parameter bounds.
framework/src/main/java/org/checkerframework/common/basetype/BaseTypeVisitor.java Switches method invocation type-argument checking to use adapted bounds from the factory helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread framework/tests/viewpointtest/MethodTypeVariableBounds.java
wmdietl and others added 7 commits July 16, 2026 14:41
AnnotatedTypeCopierWithReplacement skips executable type parameters, so
adapted method/constructor type-variable bounds were discarded and
inference still saw unadapted declaration bounds. Install the adapted
declarations, drop the redundant post-check re-adaptation helper, and
add constructor coverage.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread framework/tests/viewpointtest/ConstructorTypeVariableBounds.java Outdated
Comment thread framework/tests/viewpointtest/ConstructorTypeVariableBounds.java Outdated

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good!

@wmdietl wmdietl changed the title Use adapted bounds for method type arguments Use adapted bounds for method/constructor type arguments Aug 5, 2026
@wmdietl
wmdietl merged commit b4b66d0 into eisop:master Aug 5, 2026
42 checks passed
@aosen-xiong
aosen-xiong deleted the method-typevariables-from-use branch August 5, 2026 09:58
aosen-xiong added a commit to aosen-xiong/checker-framework that referenced this pull request Aug 5, 2026
The viewpoint test checker obtained method type parameter bounds through
AnnotatedTypeFactory#methodTypeVariablesFromUse, which fetched the raw
bounds and then viewpoint-adapted them itself. "Use adapted bounds for
method/constructor type arguments" (eisop#1850) performs that adaptation in
AbstractViewpointAdapter#viewpointAdaptMethod and
#viewpointAdaptConstructor, so the framework method duplicated it.

Remove methodTypeVariablesFromUse and its BaseTypeVisitor call site,
which restores the master implementation, and read the already-adapted
bounds from methodFromUse and constructorFromUse. Constructor
invocations are now checked as well; previously only method invocations
reported viewpointtest.lost.in.bounds. Update the expectations in the
tests added by eisop#1850, and delete ViewpointAdaptationBounds.java, whose
cases those tests cover.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants