Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8067883

Javac misses some opportunities for diagnostic simplification

    Details

    • Subcomponent:
    • Resolved In Build:
      b46
    • Verification:
      Verified

      Backports

        Description

        The method resolution diagnostic simplification framework doesn't work with generic calls, even when the cause of the mismatch does not depend on inference variables:

        <Z> void m(List<Z> z, List<String> ls) { }

        void test(List<Integer> li) {
        m(null, li);
        }

        error is this:

        Main.java:6: error: method m in class Foo cannot be applied to given types;
        m(null, li);
        ^
          required: List<Z>,List<String>
          found: <null>,List<Integer>
          reason: cannot infer type-variable(s) Z
            (argument mismatch; List<Integer> cannot be converted to List<String>)
          where Z is a type-variable:
            Z extends Object declared in method <Z>m(List<Z>,List<String>)

        When it could have been simplified into something like:

        Main.java:6: error: incompatible types: List<Integer> cannot be converted to List<String>
        m(null, li);
        ^

        Diamond related error messages also suffer from a similar issue.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  mcimadamore Maurizio Cimadamore
                  Reporter:
                  mcimadamore Maurizio Cimadamore
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: