Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9558

Wrong code for putAt on Map that is member of closure delegate

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0.3, 2.5.12
    • Fix Version/s: 4.0.0-alpha-1, 3.0.5, 2.5.13
    • Component/s: Static compilation
    • Labels:
      None
    • Environment:
      Oracle JDK8 1.8.0_162, IntelliJ CE 2019.3.4, indy enabled

      Description

       

      I'm compiling this little Closure with @CompileStatic enabled

      scriptEngine.config.tap {
        // Code generation goes wrong here    
        optimizationOptions["indy"] = true
        // This code is generated correctly
        optimizationOptions.indy = true
      }
      // Generated fault code - obviously no call to getOptimizationOptions()
      boolean var2 = true;DefaultGroovyMethods.putAt(((Class)((_main_closure1)this).getDelegate()).cast<invokedynamic>(((_main_closure1)this).getDelegate()), "indy", var2);
      // Correct code for the second line, via setProperty
      boolean bool1 = true;ScriptBytecodeAdapter.setProperty(Boolean.valueOf(bool1), null, ((CompilerConfiguration)((_main_closure1)this).getDelegate()).getOptimizationOptions(), (String)"indy");
      

      Compilation works, but I get a runtime error, which is easily explicable given the generated code:
      Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.codehaus.groovy.control.CompilerConfiguration@15d9bc04' with class 'org.codehaus.groovy.control.CompilerConfiguration' to class 'java.util.Map'

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              eddelplus Jochen Eddelbuettel
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h