Consider omitting type annotations from type error diagnostics

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • 23
    • Affects Version/s: None
    • Component/s: tools
    • None
    • b26

      Error messages like 'List<@Nullable String> cannot be assigned to ...' can be confusing, because the annotations (e.g. @Nullable) do not affect Java's type system. It might be clearer to omit the annotations when printing types in diagnostics.

      ===
      import static java.lang.annotation.ElementType.TYPE_USE;

      import java.lang.annotation.Target;
      import java.util.List;

      @Target(TYPE_USE)
      @interface A {}

      public class T {
        List<@A Number> f(List<String> xs) {
          return xs;
        }
      }
      ===

      Actual:

      $ javac -fullversion ~/T.java
      javac full version "19-ea+33-2224"
      T.java:11: error: incompatible types: List<String> cannot be converted to List<@A Number>
          return xs;
                 ^
      1 error

      Suggested:

      error: incompatible types: List<String> cannot be converted to List<Number>

            Assignee:
            Liam Miller-Cushon
            Reporter:
            Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: