Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't erase the type argument of receiver #793

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

Ao-senXiong
Copy link
Member

@Ao-senXiong Ao-senXiong commented Jun 25, 2024

Also fixes #104

for this code

public class Test<T> {
   Test <T> a;

    Test() {
        a = new Test<>();
        foo();
    }

    void foo() {}
}

error message before the change:

Test.java:6: error: [method.invocation.invalid] call to foo() not allowed on the given receiver.
        foo();
           ^
  found   : @UnderInitialization(Test.class) Test</*RAW*/>
  required: @Initialized Test</*RAW*/>

error message after the change:

Test.java:6: error: [method.invocation.invalid] call to foo() not allowed on the given receiver.
        foo();
           ^
  found   : @UnderInitialization(Test.class) Test<T extends @Initialized Object>
  required: @Initialized Test<T extends @Initialized Object>
1 error

Copy link
Member

@wmdietl wmdietl left a comment

Choose a reason for hiding this comment

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

As discussed, please add a jtreg test.

@wmdietl wmdietl assigned Ao-senXiong and unassigned wmdietl Jun 26, 2024
@wmdietl
Copy link
Member

wmdietl commented Jun 26, 2024

Maybe this would fix #104? Can you try with tests from that issue?

@Ao-senXiong
Copy link
Member Author

Maybe this would fix #104? Can you try with tests from that issue?

Just checked, this did not fix it.

@Ao-senXiong Ao-senXiong requested a review from wmdietl June 27, 2024 04:08
@Ao-senXiong Ao-senXiong assigned wmdietl and unassigned Ao-senXiong Jun 27, 2024
Copy link
Member

@wmdietl wmdietl left a comment

Choose a reason for hiding this comment

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

Thanks for starting to look into this. We should look at this properly and fix #104 while we touch this code.

*
* @compile/fail/ref=TypeArgument.out -XDrawDiagnostics -processor org.checkerframework.checker.nullness.NullnessChecker TypeArgument.java
*/
public class TypeArgument<T> {
Copy link
Member

Choose a reason for hiding this comment

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

TypeArgument is not a very descriptive name for this test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to NonRawTypeArgumentTest

checker/jtreg/nullness/type-argument/TypeArgument.out Outdated Show resolved Hide resolved
@wmdietl wmdietl assigned Ao-senXiong and unassigned wmdietl Jun 27, 2024
@Ao-senXiong Ao-senXiong requested a review from wmdietl June 27, 2024 18:57
@Ao-senXiong Ao-senXiong assigned wmdietl and unassigned Ao-senXiong Jun 27, 2024
@@ -0,0 +1,14 @@
/*
* @test
* @summary Test case for type argument in method invocation.
Copy link
Member

Choose a reason for hiding this comment

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

I find this summary confusing and don't see how this matches the code - there is no type argument there.
You need to say something about what type argument you mean.
Same with the test name 'NonRawTypeArgument` isn't very helpful - all type arguments are non-raw, otherwise there wouldn't be type arguments...

@wmdietl wmdietl assigned Ao-senXiong and unassigned wmdietl Jun 28, 2024
@Ao-senXiong Ao-senXiong requested a review from wmdietl July 3, 2024 18:36
@Ao-senXiong Ao-senXiong removed their assignment Jul 3, 2024
@Ao-senXiong
Copy link
Member Author

This is a partial fix, look into the error message in subclass and #104

@Ao-senXiong
Copy link
Member Author

#104 seems like really different issue after I debugging the code. Maybe we should merge this independently.

@Ao-senXiong
Copy link
Member Author

This f66d93d also fixes #104 now.

@wmdietl I am wondering why we have three local variables here?

AnnotatedTypeMirror methodReceiver = method.getReceiverType().getErased();
AnnotatedTypeMirror treeReceiver = methodReceiver.shallowCopy(false);
AnnotatedTypeMirror rcv = atypeFactory.getReceiverType(tree);

I think we can only use two, one for the actual receiver invoke the method and one from the method signature.

Otherwise, we need to change shallow copy because currently it also copy the annotation for type argument regardless the boolean flag.

AnnotatedDeclaredType type =
new AnnotatedDeclaredType(getUnderlyingType(), atypeFactory, declaration);
if (copyAnnotations) {
type.addAnnotations(this.getAnnotationsField());
}
type.setEnclosingType(getEnclosingType());
type.setTypeArguments(getTypeArguments());

@Ao-senXiong
Copy link
Member Author

The errors in CI are interesting:
plume-lib: This looks like error reporting use the same ATM.

> Compilation failed; see the compiler output below.
  Note: Checker Framework 3.42.0-eisop5-SNAPSHOT, branch HEAD, 2024-12-18, commit bd34749, dirty=true
  /tmp/plume-util/src/main/java/org/plumelib/util/ArraysPlume.java:1714: error: [nullness:method.invocation.invalid] call to toArray() not allowed on the given receiver.
      T[] asArray = (T[]) lst.toArray();
                                     ^
    found   : @NonNull List<T extends @Nullable Object>
    required: @NonNull List<T extends @Nullable Object>
  1 error

Daikon-part1: This looks like it fails because of handling wildcard.

daikon/Quant.java:11450: error: [nullness:method.invocation.invalid] call to toArray() not allowed on the given receiver.
      return java.lang.reflect.Array.get(((java.util.AbstractCollection<?>)o).toArray(), (int)i);
                                                                                     ^
  found   : @NonNull AbstractCollection<? extends @Nullable Object>
  required: @NonNull AbstractCollection<capture#09 extends @Nullable Object>
daikon/Quant.java:12162: error: [nullness:method.invocation.invalid] call to toArray() not allowed on the given receiver.
      return (String)java.lang.reflect.Array.get(((java.util.AbstractCollection<?>)o).toArray(), (int)i);
                                                                                             ^
  found   : @NonNull AbstractCollection<? extends @Nullable Object>
  required: @NonNull AbstractCollection<capture#010 extends @Nullable Object>
10 errors
make: *** [Makefile:922: typecheck-nullness] Error 1
make: Leaving directory '/home/runner/work/checker-framework/daikon/java'

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.

Annotations on any type arguments of a method receiver are ignored
2 participants