Skip to content

Use adapted bounds for method type arguments#1850

Open
aosen-xiong wants to merge 10 commits into
eisop:masterfrom
aosen-xiong:method-typevariables-from-use
Open

Use adapted bounds for method type arguments#1850
aosen-xiong wants to merge 10 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
Comment thread framework/tests/viewpointtest/ConstructorTypeVariableBounds.java
* Returns the receiver type used to viewpoint-adapt a method invocation.
*
* @param tree a method invocation tree
* @return the receiver type, or null if the invocation has no receiver

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.

Cross-reference getReceiverType and explain differences!

AnnotatedTypeMirror tv = combineTypeWithType(receiverType, typeVariable);
mappings.put(typeVariable, tv);
// Adapt type-variable declarations separately. AnnotatedTypeCopierWithReplacement does not
// replace executable type parameters (see its visitTypeVariable), so install the adapted

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.

Shouldn't the AnnotatedTypeCopierWithReplacement do this? Do you understand the reasoning given there?

for (AnnotatedTypeVariable typeVariable : typeVariables) {
AnnotatedTypeVariable adapted =
(AnnotatedTypeVariable) combineTypeWithType(receiverType, typeVariable);
mappings.put(typeVariable, adapted);

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.

Do we still need to add it to the mapping? Why add it to the mapping if AnnotatedTypeCopierWithReplacement doesn't do anything with the method type variables?

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