type annotations on local variables are classified after the local var initializer has been type checked

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Affects Version/s: 25
    • Component/s: tools
    • None

      Consider the following example

      class Test {
          @Target(ElementType.TYPE_USE)
          @interface TypeAnno { }

          @TypeAnno Supplier<String> r_f_i = () -> "r_f_i"; // ok
          static @TypeAnno Supplier<String> r_f_s = () -> "r_f_s"; // ok

          {
              @TypeAnno Supplier<String> r_init_i = () -> "r_init_i"; // missing
          }

          static {
              @TypeAnno Supplier<String> r_init_s = () -> "r_init_s"; // missing
          }

          void m() {
              @TypeAnno Supplier<String> r_m_i = () -> "r_m_i"; // missing
          }

          static void g() {
              @TypeAnno Supplier<String> r_g_s = () -> "r_g_s"; // missing
          }

          void h() {
              t_cr(() -> "t_cr"); // ok
          }

          void i() {
              t_no_cr((@TypeAnno Supplier<String>)() -> "t_no_cr"); // ok
          }

          void j() {
              t_no_cr((java.io.Serializable & @TypeAnno Supplier<String>)() -> "t_no_cr"); // ok
          }

          void t_cr(@TypeAnno Supplier<String> r_p) { }
          void t_no_cr(@TypeAnno Supplier<String> r_p) { }
      }

      This demonstrates the use of type annotations on variable declarations with a lambda initializer. By manually inspecting the AST, it's possible to see that the type annotations are missing in the lambda target type in the cases highlighted (local variable declaration).

            Assignee:
            Jan Lahoda
            Reporter:
            Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: