Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
3.0.9
-
None
-
None
Description
The following code runs without problem in Groovy 2.5.14:
import groovy.transform.CompileDynamic import groovy.transform.CompileStatic @CompileStatic class DynamicArrayAccess { @CompileDynamic DynamicArrayAccess() { Node node = loadXml() println node.b[0].text() } private static Node loadXml() { new StringReader("<a><b>hello</b></a>").withCloseable { new XmlParser().parse(it) } } static void main(String[] args) { new DynamicArrayAccess() } }
However, if you try to run it in Groovy 3.0.9, you'll get an exception during compilation. Extracting problematic code to a separate method fixes the problem.
BUG! exception in phase 'class generation' in source unit '/home/nik/IdeaProjects/untitled19/src/main/groovy/DynamicArrayAccess.groovy' At line 9 column 21 On receiver: node.b with message: getAt and arguments: 0 This method should not have been called. Please try to create a simple example reproducing this error and file a bug report at https://issues.apache.org/jira/browse/GROOVY at org.codehaus.groovy.classgen.asm.sc.StaticTypesCallSiteWriter.makeSingleArgumentCall(StaticTypesCallSiteWriter.java:582) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeSingleArgumentCall(InvocationWriter.java:623) at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.evaluateBinaryExpression(BinaryExpressionHelper.java:590) at org.codehaus.groovy.classgen.asm.BinaryExpressionMultiTypeDispatcher.evaluateBinaryExpression(BinaryExpressionMultiTypeDispatcher.java:209) at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.eval(BinaryExpressionHelper.java:319) at org.codehaus.groovy.classgen.AsmClassGenerator.visitBinaryExpression(AsmClassGenerator.java:708) at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:58) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeUncachedCall(InvocationWriter.java:338) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:387) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:121) at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:649) at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:456) at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:140) at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:839) at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:76) at org.codehaus.groovy.classgen.AsmClassGenerator.visitTupleExpression(AsmClassGenerator.java:1571) at org.codehaus.groovy.classgen.AsmClassGenerator.visitArgumentlistExpression(AsmClassGenerator.java:1526) at org.codehaus.groovy.ast.expr.ArgumentListExpression.visit(ArgumentListExpression.java:73) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeUncachedCall(InvocationWriter.java:357) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:387) at org.codehaus.groovy.classgen.asm.InvocationWriter.makeCall(InvocationWriter.java:121) at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.makeCall(StaticInvocationWriter.java:649) at org.codehaus.groovy.classgen.asm.InvocationWriter.writeInvokeMethod(InvocationWriter.java:456) at org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.writeInvokeMethod(StaticInvocationWriter.java:140) at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethodCallExpression(AsmClassGenerator.java:839) at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:76) at org.codehaus.groovy.classgen.asm.StatementWriter.writeExpressionStatement(StatementWriter.java:635) at org.codehaus.groovy.classgen.AsmClassGenerator.visitExpressionStatement(AsmClassGenerator.java:687) at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40) at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:94) at org.codehaus.groovy.classgen.asm.sc.StaticTypesStatementWriter.writeBlockStatement(StaticTypesStatementWriter.java:78) at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:618) at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:138) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:111) at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:462) at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:409) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructor(ClassCodeVisitorSupport.java:101) at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructor(AsmClassGenerator.java:551) at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1089) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52) at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:272) at org.codehaus.groovy.control.CompilationUnit$3.call(CompilationUnit.java:797) at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
Attachments
Issue Links
- is related to
-
GROOVY-10457 Compilation of constructor calls inside CompileDynamic constructors fails with ArrayIndexOutOfBoundsException
- Closed
- relates to
-
GROOVY-10457 Compilation of constructor calls inside CompileDynamic constructors fails with ArrayIndexOutOfBoundsException
- Closed