t-rasmud / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
2 stars 2 forks source link

Lower bound on receiver type argument not resolved correctly #165

Open t-rasmud opened 4 years ago

t-rasmud commented 4 years ago

In the test case below,

import org.checkerframework.checker.determinism.qual.Det;
import org.checkerframework.checker.determinism.qual.NonDet;

public class ReceiverLowerBoundIssue {

    static <T> void method(@NonDet ReceiverLower<@NonDet T> arg) {}

    void testCall(@NonDet ReceiverLower<@Det String> arg) {
        // :: error: (argument.type.incompatible)
        method(arg);
    }

    void testCall2(@NonDet ReceiverLower<@Det String> arg) {
        // :: error: (method.invocation.invalid)
        arg.test();
    }
}

class ReceiverLower<T> {
    void test(@NonDet ReceiverLower<@NonDet T> this) {}
}

calling method(arg) should have the same behavior as calling arg.test(). The static method method has one parameter with type argument whose lower bound is @NonDet. The signature of the method test declares the lower bound of its receiver type argument to be @NonDet. However, running the determinism checker on this example gives the following output:

javac -processor determinism checker/tests/determinism/ReceiverLowerBoundIssue.java

checker/tests/determinism/ReceiverLowerBoundsIssue.java:10: error: [argument.type.incompatible] incompatible types in argument.
        method(arg);
                      ^
  found   : @NonDet ReceiverLower<@Det String>
  required: @NonDet ReceiverLower<@NonDet String>
1 error

i.e, the expected error on the method invocation arg.test(); is not reported by the checker.

t-rasmud commented 4 years ago

@smillst Is this related to the issue about receiver type arguments that you are working on?

t-rasmud commented 4 years ago

Same as #3124

smillst commented 4 years ago

Currently annotations on receiver type arguments are ignored; writing one is that same as not writing one. I'm working on fixing this.