t-rasmud / checker-framework

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

Incorrect annotation name in error message #147

Open jwaataja opened 4 years ago

jwaataja commented 4 years ago

Consider the following class.

import org.checkerframework.checker.determinism.qual.*;

class C<T extends @PolyDet Object> {
    public @PolyDet("up") T f(@PolyDet int i) {
        return null;
    }

    public T callF(@PolyDet C<T> list, @PolyDet int index) {
        return list.f(index);
    }
}

There is an error in this class, which is that the return type of the second method should be @PolyDet("up"). In the determinism checker I get the following error.

C.java:9: error: [return.type.incompatible] incompatible types in return.
        return list.f(index);
                     ^
  type of expression: T extends @PolyDet("") Object
  method return type: T extends @PolyDet Object

The message is incorrect because the type of the expression is @PolyDet("") rather than @PolyDet("up").

smillst commented 4 years ago

Here's the error using -AprintVerboseGenerics.

/Users/smillst/tmp/C.java:9: error: [return.type.incompatible] incompatible types in return.
        return list.f(index);
                     ^
  type of expression: T[ extends @PolyDet("") Object super @PolyDet("") Void]
  method return type: T[ extends @PolyDet Object super @Det Void]
1 error

I think this is related to https://github.com/typetools/checker-framework/issues/2432.