You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/10/05 15:30:00 UTC

[jira] [Resolved] (GROOVY-6271) Groovyc AIOBE when using CompileStatic with generics

     [ https://issues.apache.org/jira/browse/GROOVY-6271?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-6271.
---------------------------------
    Resolution: Fixed

Works under 4.0b1 if literal "4.0" is changed to "4.0d".

> Groovyc AIOBE when using CompileStatic with generics
> ----------------------------------------------------
>
>                 Key: GROOVY-6271
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6271
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.2.0-beta-1, 2.4.0-rc-1
>            Reporter: Paul King
>            Priority: Major
>
> For this code (left mostly in Java-ish style in case you want to convert back to Java to test it):
> {code}
> @Grab('org.functionaljava:functionaljava:3.1')
> import static fj.data.hlist.HList.HCons;
> import static fj.data.hlist.HList.HNil;
> import static fj.data.hlist.HList.HAppend.append;
> import static fj.data.hlist.HList.HAppend;
> import static fj.data.hlist.HList.nil;
> import groovy.transform.CompileStatic
> @CompileStatic
> public class HListExample {
>   public static void main(String[] args) {
>     final HCons<String, HCons<Integer, HCons<Boolean, HNil>>> a =
>       nil().extend(true).extend(3).extend("Foo");
>     final HCons<Double, HCons<String, HCons<Integer[], HNil>>> b =
>       nil().extend([1, 2] as Integer[]).extend("Bar").extend(4.0);
> //      nil().extend(new Integer[]{1, 2}).extend("Bar").extend(4.0);
>     final HAppend<HNil, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
>       HCons<Double, HCons<String, HCons<Integer[], HNil>>>> zero = append();
>     final HAppend<HCons<Boolean, HNil>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
>       HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>> one = append(zero);
>     final HAppend<HCons<Integer, HCons<Boolean, HNil>>, HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
>       HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>> two = append(one);
>     final HAppend<HCons<String, HCons<Integer, HCons<Boolean, HNil>>>,
>       HCons<Double, HCons<String, HCons<Integer[], HNil>>>,
>         HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>>> three = append(two);
>     final HCons<String, HCons<Integer, HCons<Boolean, HCons<Double, HCons<String, HCons<Integer[], HNil>>>>>> x = three.append(a, b);
>     System.out.println(x.head()); // Foo
>     System.out.println(x.tail().tail().tail().tail().head()); // Bar
>   }
> }
> {code}
> works (with minor mods in Java) and without @CompileStatic but with @CompileStatic I get three unexpected errors:
> {noformat}
> Groovyc: java.lang.ArrayIndexOutOfBoundsException: 1
> 	at org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders(GenericsUtils.java:128)
> 	at org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders(GenericsUtils.java:107)
> 	at org.codehaus.groovy.ast.GenericsType$GenericsTypeMatcher.compareGenericsWithBound(GenericsType.java:343)
> 	at org.codehaus.groovy.ast.GenericsType$GenericsTypeMatcher.checkGenerics(GenericsType.java:275)
> 	at org.codehaus.groovy.ast.GenericsType$GenericsTypeMatcher.matches(GenericsType.java:246)
> 	at org.codehaus.groovy.ast.GenericsType.isCompatibleWith(GenericsType.java:173)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isAssignableTo(StaticTypeCheckingSupport.java:361)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.allParametersAndArgumentsMatch(StaticTypeCheckingSupport.java:222)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.chooseBestMethod(StaticTypeCheckingSupport.java:1001)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.findMethod(StaticTypeCheckingVisitor.java:3018)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitStaticMethodCallExpression(StaticTypeCheckingVisitor.java:1777)
> 	at org.codehaus.groovy.ast.expr.StaticMethodCallExpression.visit(StaticMethodCallExpression.java:44)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBinaryExpression(StaticTypeCheckingVisitor.java:444)
> 	at org.codehaus.groovy.ast.CodeVisitorSupport.visitDeclarationExpression(CodeVisitorSupport.java:245)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitDeclarationExpression(ClassCodeVisitorSupport.java:107)
> 	at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:86)
> 	at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:69)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:193)
> 	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
> 	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
> 	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:1409)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:1686)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:1659)
> 	at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:120)
> 	at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1055)
> 	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:172)
> 	at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:110)
> 	at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:60)
> 	at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:132)
> 	at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:176)
> 	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1036)
> 	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:572)
> 	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:550)
> 	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:527)
> 	at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:54)
> 	at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:80)
> 	at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:85)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:601)
> 	at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)
> {noformat}
> {noformat}
> Groovyc: [Static type checking] - Cannot find matching method fj.data.hlist.HList$HCons#extend(int). Please check if the declared type is right and if the method exists.
> {noformat}
> {noformat}
> Groovyc: [Static type checking] - Cannot find matching method fj.data.hlist.HList$HCons#extend(java.lang.String). Please check if the declared type is right and if the method exists.
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)