[jira] [Commented] (GROOVY-7419) Static Compilation with Diamond of local EnumMap<>

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-7419) Static Compilation with Diamond of local EnumMap<>

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/GROOVY-7419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14537544#comment-14537544 ]

Shil Sinha commented on GROOVY-7419:
------------------------------------

This appears to happen as a result of the static type checker using the generic types of the type of the first argument to the constructor (Class<Blah>) instead of the generic types of the left hand type (Map<Blah, Object>) when inferring the diamond type.

> Static Compilation with Diamond of local EnumMap<>
> ---------------------------------------------------
>
>                 Key: GROOVY-7419
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7419
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 2.4.3
>         Environment: Groovy Version: 2.4.3
> JVM: 1.7.0_25
> Vendor: Oracle Corporation
> OS: Windows 7
>            Reporter: Dan Sheehan
>            Assignee: C├ędric Champeau
>
> {code:title=Foo.groovy}
> import groovy.transform.CompileStatic
> @CompileStatic
> class Foo
> {
>     enum Blah {
>         ONE, TWO
>     }
>     void broken()
>     {
>         Map<Blah,Object> foo = new EnumMap<>(Blah.class);
>         assert foo.size() == 0;
>     }
>     void works()
>     {
>         Map<Blah,Object> foo = new HashMap<>();
>         assert foo.size() == 0;
>     }
> }
> {code}
> {noformat}
> "c:\Program Files (x86)\Groovy\Groovy-2.4.3\bin\groovyc" Foo.groovy
> {noformat}
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> General error during instruction selection: 1
> java.lang.ArrayIndexOutOfBoundsException: 1
>         at org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders(GenericsUtils.java:164)
>         at org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders(GenericsUtils.java:136)
>         at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.typeCheckMethodsWithGenerics(StaticTypeCheckingSupport.java:1342)
>         at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.typeCheckMethodsWithGenerics(StaticTypeCheckingSupport.java:1323)
>         at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.typeCheckMethodsWithGenericsOrFail(StaticTypeCheckingVisitor.java:4476)
>         at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:2926)
>         at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethodCallExpression(StaticCompilationVisitor.java:294)
>         at org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:64)
>         at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBinaryExpression(StaticTypeCheckingVisitor.java:548)
>         at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:49)
>         at org.codehaus.groovy.ast.CodeVisitorSupport.visitBooleanExpression(CodeVisitorSupport.java:166)
>         at org.codehaus.groovy.ast.expr.BooleanExpression.visit(BooleanExpression.java:40)
>         at org.codehaus.groovy.ast.CodeVisitorSupport.visitAssertStatement(CodeVisitorSupport.java:77)
>         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitAssertStatement(ClassCodeVisitorSupport.java:158)
>         at org.codehaus.groovy.ast.stmt.AssertStatement.visit(AssertStatement.java:47)
>         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:1770)
>         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
>         at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2103)
>         at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2062)
>         at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:160)
>         at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1083)
>         at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
>         at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:247)
>         at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:119)
>         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:1052)
>         at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:588)
>         at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:566)
>         at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:543)
>         at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:522)
>         at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:59)
>         at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:215)
>         at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:148)
>         at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:178)
>         at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:162)
>         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:606)
>         at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
>         at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
> 1 error
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)