Skip to content

Fix viewpoint-adapted varargs type#903

Open
aosen-xiong wants to merge 14 commits into
eisop:masterfrom
aosen-xiong:invoke-viewpointadapter-constructor
Open

Fix viewpoint-adapted varargs type#903
aosen-xiong wants to merge 14 commits into
eisop:masterfrom
aosen-xiong:invoke-viewpointadapter-constructor

Conversation

@aosen-xiong

@aosen-xiong aosen-xiong commented Sep 9, 2024

Copy link
Copy Markdown
Collaborator

Fixes #386

Recompute the cached varargs type after viewpoint adaptation updates executable parameter types.

@aosen-xiong
aosen-xiong requested a review from wmdietl September 30, 2024 21:24
@aosen-xiong aosen-xiong assigned wmdietl and unassigned aosen-xiong Sep 30, 2024

@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.

Can you add some test cases that illustrate what goes wrong without this change?

@wmdietl wmdietl assigned aosen-xiong and unassigned wmdietl Oct 3, 2024
@aosen-xiong aosen-xiong removed their assignment May 27, 2026
@aosen-xiong
aosen-xiong marked this pull request as draft May 27, 2026 03:20
@aosen-xiong aosen-xiong changed the title Invoke viewpoint adapter at correct place Fix viewpoint-adapted varargs type Jun 20, 2026
@aosen-xiong
aosen-xiong marked this pull request as ready for review June 20, 2026 14:06
@aosen-xiong

Copy link
Copy Markdown
Collaborator Author

This does not fix #828, it is a very deep issue that requires hard investigation.

Copilot AI review requested due to automatic review settings July 16, 2026 16:02

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

Fixes EISOP issue #386 by ensuring that an AnnotatedExecutableType’s cached varargs type is recomputed after viewpoint adaptation mutates the executable’s parameter types, so varargs checking uses the adapted (correct) type.

Changes:

  • Recompute varargType after viewpoint adaptation in AbstractViewpointAdapter for both constructors and methods.
  • Update/extend viewpoint varargs tests to expect varargs.type.incompatible where appropriate.
  • Add a dedicated regression test for issue #386 and record the fix in the changelog.

Reviewed changes

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

File Description
framework/tests/viewpointtest/VarargsConstructor.java Updates expected diagnostics to include varargs.type.incompatible after the fix.
framework/tests/viewpointtest/Issue386.java Adds regression coverage for viewpoint-adapted varargs on constructors and methods.
framework/src/main/java/org/checkerframework/framework/type/AbstractViewpointAdapter.java Recomputes cached varargs type after updating executable parameter types via viewpoint adaptation.
docs/CHANGELOG.md Notes closure of #386.

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

Comment thread framework/tests/viewpointtest/Issue386.java
Comment thread framework/tests/viewpointtest/Issue386.java

void foo() {
// :: error: (new.class.type.invalid)
// :: error: (new.class.type.invalid) :: error: (varargs.type.incompatible)

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.

What is the intuition behind this new error? There are no arguments to this constructor invocation, so what is incompatible?

@aosen-xiong aosen-xiong Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The err msg is:

VarargsConstructor.java:35: error: [new.class.type.invalid]
type annotation [@Lost] can not be applied to object creation

VarargsConstructor.java:35: error: [varargs.type.incompatible]
incompatible types in varargs.
  found   : @Lost Object @Top []
  required: @Lost Object @Top []

A zero-argument varargs invocation still creates an implicit empty array. The error occurs because viewpoint adaptation produces @Lost, which is non-reflexive in this test checker. With #1173, the error would be gone.

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.

What is the connection to #1173? 1173 is about lost receivers for poly declared receiver methods. This is about arrays?

If the var args array is definitely empty, the Lost component type cannot do any harm. It seems overly conservative to forbid this call, doesn't it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because in #1173 we changed Lost to be a subtype of Lost, this varags.type.incompatible error message will be gone.

Okay, I see your points.

I think even after the change in #1173, we should have

  1. If the argument is empty, allow the call.
  2. If the argument is not empty and the var arg is adapted to have a lost type, reject the call.

@wmdietl wmdietl assigned aosen-xiong and unassigned wmdietl Jul 17, 2026
@aosen-xiong aosen-xiong assigned wmdietl and unassigned aosen-xiong Jul 17, 2026
@wmdietl wmdietl assigned aosen-xiong and unassigned wmdietl Jul 17, 2026
@aosen-xiong aosen-xiong assigned wmdietl and unassigned aosen-xiong Jul 25, 2026
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.

varargType is not correct for viewpoint adaption if the method or constructor accepts varargs

3 participants