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

Internal compiler error when using constructor as Function

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0.6
    • Fix Version/s: None
    • Labels:
      None

      Description

      (Background that I don't think is relevant, but in case: I have written some extension methods in plain Java and am pulling them in as Maven dependencies. The STC does correctly identify these methods and expect appropriate parameters.)

      When invoking a method that takes a Function<? super A, R> mapper, I am trying to pass a constructor method reference as the parameter: .map(GnomeDto::new). This appears to get past canonicalization happily enough, but the actual class generation throws an internal compiler error:

      [ERROR] java.lang.ArrayIndexOutOfBoundsException: Internal compiler error while compiling /home/christopher/gnomes/src/main/groovy/com/example/gnomes/GnomeController.groovy[ERROR] Method: org.codehaus.groovy.ast.MethodNode@25e9f5e6[com.example.gnomes.GnomeController#com.example.gnomes.GnomeDto ctorRef$record$0(java.lang.Object)][ERROR] Line -1, expecting casting to com.example.gnomes.GnomeDto but operand stack is empty[ERROR]         at org.codehaus.groovy.classgen.asm.OperandStack.throwExceptionForNoStackElement(OperandStack.java:331)[ERROR]         at org.codehaus.groovy.classgen.asm.OperandStack.doConvertAndCast(OperandStack.java:336)[ERROR]         at org.codehaus.groovy.classgen.asm.OperandStack.doGroovyCast(OperandStack.java:300)[ERROR]         at org.codehaus.groovy.classgen.asm.StatementWriter.writeReturn(StatementWriter.java:607)[ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitReturnStatement(AsmClassGenerator.java:662)[ERROR]         at org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.java:73)[ERROR]         at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:94)[ERROR]         at org.codehaus.groovy.classgen.asm.sc.StaticTypesStatementWriter.writeBlockStatement(StaticTypesStatementWriter.java:78)[ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:598)[ERROR]         at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)[ERROR]         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:138)[ERROR]         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:111)[ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:461)[ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:408)[ERROR]         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:106)[ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:537)[ERROR]         at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1110)[ERROR]         at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1092)[ERROR]         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)[ERROR]         at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:270)[ERROR]         at org.codehaus.groovy.control.CompilationUnit$3.call(CompilationUnit.java:797)[ERROR]         at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942)[ERROR]         at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)[ERROR]         at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)[ERROR]         at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:610)[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:566)[ERROR]         at org.codehaus.gmavenplus.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:214)[ERROR]         at org.codehaus.gmavenplus.mojo.AbstractCompileMojo.doCompile(AbstractCompileMojo.java:288)[ERROR]         at org.codehaus.gmavenplus.mojo.CompileMojo.execute(CompileMojo.java:69)[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)[ERROR]         at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)[ERROR]         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)[ERROR]         at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)[ERROR]         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)[ERROR]         at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:566)[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
      

      This same code appears to compile correctly if I explicitly instruct .map(GnomeDto::new as Function).

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              chrylis Christopher Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: