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

Codegen throws ClassCastException for BinaryNode in switch case expression

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • None
    • core-libs
    • None
    • b82
    • Verified

    Description

      The following code should print "ok":

      var x = 1;

      switch (x) {
        case foo = false, 1:
           print("ok");
      }

      but throws ClassCastException in Nashorn:

      Exception in thread "main" java.lang.ClassCastException: jdk.nashorn.internal.ir.BinaryNode cannot be cast to jdk.nashorn.internal.ir.LiteralNode
      at jdk.nashorn.internal.codegen.CodeGenerator.enter(CodeGenerator.java:1795)
      at jdk.nashorn.internal.ir.SwitchNode.accept(SwitchNode.java:93)
      at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:305)
      at jdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:418)
      at jdk.nashorn.internal.runtime.Context.compile(Context.java:882)
      at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:862)
      at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:499)
      at jdk.nashorn.tools.Shell.runScripts(Shell.java:285)
      at jdk.nashorn.tools.Shell.run(Shell.java:167)
      at jdk.nashorn.tools.Shell.main(Shell.java:136)
      at jdk.nashorn.tools.Shell.main(Shell.java:115)

      Attachments

        Activity

          People

            lagergren Marcus Lagergren
            hannesw Hannes Wallnoefer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: