checker-framework icon indicating copy to clipboard operation
checker-framework copied to clipboard

Improvement of error message in [type.invalid.conflicting.annos] error

Open Kakarot-SSJ4 opened this issue 6 years ago • 2 comments

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.

Kakarot-SSJ4 avatar Apr 01 '19 21:04 Kakarot-SSJ4

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.

kelloggm avatar Apr 01 '19 21:04 kelloggm

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.

Kakarot-SSJ4 avatar Apr 02 '19 17:04 Kakarot-SSJ4