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

Annotation on Decomposed Record Component in Enhanced For Loop Fails Compilation

    XMLWordPrintable

Details

    • b27
    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      ➜ src java --version
      openjdk 20.0.2 2023-07-18
      OpenJDK Runtime Environment Corretto-20.0.2.9.1 (build 20.0.2+9-FR)
      OpenJDK 64-Bit Server VM Corretto-20.0.2.9.1 (build 20.0.2+9-FR, mixed mode, sharing)
      ➜ src uname -a
      Linux fedora 6.3.12-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 6 04:05:18 UTC 2023 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Compilation fails for decomposed record component with annotation declared as 'var'.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      ➜ src cat CompilationBug.java
      import java.util.List;

      public class CompilationBug {
          void m() {
              //for (R(@A var x) : List.of(new R(1))) {} // won't compile
              for (R(@A Integer x) : List.of(new R(1))) {} // ok
          }

          @interface A {
          }

          record R(Integer x) {
          }
      }
      ➜ src javac CompilationBug.java --enable-preview --release 20
      Note: CompilationBug.java uses preview features of Java SE 20.
      Note: Recompile with -Xlint:preview for details.
      ➜ src cat CompilationBug.java
      import java.util.List;

      public class CompilationBug {
          void m() {
              for (R(@A var x) : List.of(new R(1))) {} // won't compile
              for (R(@A Integer x) : List.of(new R(1))) {} // ok
          }

          @interface A {
          }

          record R(Integer x) {
          }
      }
      ➜ src javac CompilationBug.java --enable-preview --release 20
      Note: CompilationBug.java uses preview features of Java SE 20.
      Note: Recompile with -Xlint:preview for details.
      An exception has occurred in the compiler (20.0.2). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      java.lang.AssertionError
              at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
              at jdk.compiler/com.sun.tools.javac.util.Assert.checkNonNull(Assert.java:62)
              at jdk.compiler/com.sun.tools.javac.comp.Check.validateTypeAnnotation(Check.java:3131)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitAnnotation(Attr.java:5662)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:3005)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitModifiers(TreeScanner.java:393)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCModifiers.accept(JCTree.java:3034)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitVarDef(Attr.java:5702)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1018)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitBindingPattern(TreeScanner.java:307)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBindingPattern.accept(JCTree.java:2287)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitRecordPattern(TreeScanner.java:333)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCRecordPattern.accept(JCTree.java:2481)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitForeachLoop(TreeScanner.java:165)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:1232)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitBlock(Attr.java:5759)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1088)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitMethodDef(Attr.java:5695)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitClassDef(Attr.java:5754)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:810)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.validateTypeAnnotations(Attr.java:5651)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5625)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5485)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5309)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5248)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1331)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:960)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
      printing javac parameters to: /home/nick/IdeaProjects/tester/src/javac.20230722_221519.args


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      File should compile
      ACTUAL -
      Failure to compile:
      java.lang.AssertionError
              at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
              at jdk.compiler/com.sun.tools.javac.util.Assert.checkNonNull(Assert.java:62)
              at jdk.compiler/com.sun.tools.javac.comp.Check.validateTypeAnnotation(Check.java:3131)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitAnnotation(Attr.java:5662)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:3005)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitModifiers(TreeScanner.java:393)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCModifiers.accept(JCTree.java:3034)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitVarDef(Attr.java:5702)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:1018)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitBindingPattern(TreeScanner.java:307)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBindingPattern.accept(JCTree.java:2287)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitRecordPattern(TreeScanner.java:333)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCRecordPattern.accept(JCTree.java:2481)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitForeachLoop(TreeScanner.java:165)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:1232)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitBlock(Attr.java:5759)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1088)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitMethodDef(Attr.java:5695)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
              at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
              at jdk.compiler/com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitClassDef(Attr.java:5754)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:810)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.validateTypeAnnotations(Attr.java:5651)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5625)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5485)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5309)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5248)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1331)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:960)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)


      ---------- BEGIN SOURCE ----------
      import java.util.List;

      public class CompilationBug {
          void m() {
              for (R(@A var x) : List.of(new R(1))) {} // won't compile
              for (R(@A Integer x) : List.of(new R(1))) {} // ok
          }

          @interface A {
          }

          record R(Integer x) {
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Declare a typed variable.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              abimpoudis Angelos Bimpoudis
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: