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

Incorrect record component type in record patterns

    XMLWordPrintable

Details

    • b27

    Description

      Consider code like this:
      ---
      public class Test7 {

          interface Intf<A> {
          }

          record Rec<T>(T a) implements Intf<T> {

          }

          static boolean test(Intf<? super String> p) {
              return p instanceof Rec<? super String>(var a);
          }

          public static void main(String... args) {
              boolean res = test(new Rec<>(new Object()));
              if (!res) throw new AssertionError();
          }

      }
      ---

      Compiling this code and running it fails, as the matching fails.

      The reason matching fails is that the type of `var a` is determined to be `String`, but should be `Object`.

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              jlahoda Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: