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

Problem with generic pattern matching results in internal compiler error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 24
    • 21, 23, 24
    • tools
    • master
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The code leads to compiler crashing, without providing any error explaining why the code is incorrect

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      prints 21 to the standard output
      ACTUAL -
      Executing pre-compile tasks…
      Running 'before' tasks
      Checking sources
      Copying resources... [Bug]
      Checking dependencies… [Bug]
      Dependency analysis found 0 affected files
      Updating dependency information… [Bug]
      Parsing java… [Bug]
      java: An exception has occurred in the compiler (21.0.4). 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: java.lang.ClassCastException: class com.sun.tools.javac.code.Symbol$TypeVariableSymbol cannot be cast to class com.sun.tools.javac.code.Symbol$ClassSymbol (com.sun.tools.javac.code.Symbol$TypeVariableSymbol and com.sun.tools.javac.code.Symbol$ClassSymbol are in module jdk.compiler of loader 'app')
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.reduceBindingPatterns(Flow.java:845)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.reduceNestedPatterns(Flow.java:1014)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.exhausts(Flow.java:782)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitSwitchExpression(Flow.java:737)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCSwitchExpression.accept(JCTree.java:1399)
      java: at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:50)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:455)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitReturn(Flow.java:1189)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1728)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStat(Flow.java:515)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanStats(Flow.java:523)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitBlock(Flow.java:615)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitMethodDef(Flow.java:579)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:916)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitClassDef(Flow.java:559)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:814)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.scanDef(Flow.java:501)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.visitClassDef(Flow.java:551)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.analyzeTree(Flow.java:1251)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow$AliveAnalyzer.analyzeTree(Flow.java:1243)
      java: at jdk.compiler/com.sun.tools.javac.comp.Flow.analyzeTree(Flow.java:229)
      java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1419)
      java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1393)
      java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:976)
      java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
      java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
      java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
      java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
      java: at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:238)
      java: at org.jetbrains.jps.incremental.java.JavaBuilder.lambda$compileJava$2(JavaBuilder.java:516)
      java: at org.jetbrains.jps.incremental.java.JavaBuilder.invokeJavac(JavaBuilder.java:578)
      java: at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:514)
      java: at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:358)
      java: at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:283)
      java: at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:237)
      java: at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1609)
      java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1238)
      java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1389)
      java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1203)
      java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:971)
      java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:527)
      java: at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:236)
      java: at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:135)
      java: at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:387)
      java: at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:212)
      java: at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:211)
      java: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
      java: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
      java: at java.base/java.lang.Thread.run(Thread.java:1583)
      java: Compilation failed: internal java compiler error
      Dependency analysis found 0 affected files
      Errors occurred while compiling module 'Bug'
      javac 21.0.4 was used to compile java sources
      Finished, saving caches…
      Compilation failed: errors: 1; warnings: 0
      Executing post-compile tasks…
      Synchronizing output directories…
      13/09/2024 22:36 - Build completed with 1 error and 0 warnings in 4 sec, 79 ms

      ---------- BEGIN SOURCE ----------

      public class Main {
      public static void main(String[] args) {
      Option<Integer> optionInteger = new Option.Some<>(21);
      Number number = Option.unwrapOrElse(optionInteger, 5.2);
      System.out.println(number);
      }

      sealed interface Option<T> permits Option.Some, Option.None {
      record Some<T>(T value) implements Option<T> {}
      record None<T>() implements Option<T> {}

      static <T, T2 extends T> T unwrapOrElse(Option<T2> option, T defaultValue) {
      return switch (option) {
      case Option.Some(T2 value) -> value;
      case Option.None<T2> __ -> defaultValue;
      };
      }
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: