checker-framework
checker-framework copied to clipboard
Improvement of error message in [type.invalid.conflicting.annos] error
Consider the following code:
import org.checkerframework.common.value.qual.*;
import org.checkerframework.checker.index.qual.*;
class ltlength{
public void check(int[] data, `@IndexFor`("#1") `@LTLengthOf`(value = {"#1"}, offset = {"1"}) int offset){
}
}
Run it by typing in the terminal:
javac -processor org.checkerframework.checker.index.IndexChecker ltlength.java
Output:
ltlength.java:5: error: [type.invalid.conflicting.annos] invalid type: conflicting annotations [`@LTLengthOf`(value="data", offset="1"), `@LTLengthOf`(value="data", offset={})] in type "`@LTLengthOf`(value="data", offset="1") `@LTLengthOf`(value="data", offset={}) int"
public void check(int[] data, `@IndexFor`("#1") `@LTLengthOf`(value = {"#1"}, offset = {"1"}) int offset){
This error is produced because @IndexFor("#1") is implemented as @LTLengthOf("#1") which conflicts with the second annotation @LTLengthOf(value = {"#1"}, offset = {"1"}).
But, in the error message, there is no mention of @IndexFor("#1") being compared as @LTLengthOf("#1") which may confuse the programmer as to why this error is being produced.
This seems like a generic problem with any kind of aliased annotation.
What do you suggest we do to solve it? @IndexFor does appear in the error message, though I agree that the message is somewhat confusing.
A better error message would be to first state what annotations are conflicting as written in the code, then the interpretation by the compiler separately. The distinction would enable the programmer to identify the error better.