[ https://issues.apache.org/jira/browse/GROOVY-7538?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15027613#comment-15027613 ]
ASF GitHub Bot commented on GROOVY-7538: ---------------------------------------- GitHub user fpavageau opened a pull request: https://github.com/apache/incubator-groovy/pull/196 GROOVY-7538 Resolve placeholder return types correctly This solves the first half of [GROOVY-7538](https://issues.apache.org/jira/browse/GROOVY-7538). I've tried to replace the test in `Groovy7538Bug` by a new one in `GenericsSTCTest`, but ran into another issue while trying to implement the test purely in Groovy (I'll open a new ticket on https://issues.apache.org/). You can merge this pull request into a Git repository by running: $ git pull https://github.com/fpavageau/incubator-groovy GROOVY-7538-sub-type-to-super-type Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-groovy/pull/196.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #196 ---- commit 0c83e7e389bff6e964d11154eb558a9eb1ccae3a Author: Frank Pavageau <fpavag...@ekino.com> Date: 2015-11-01T21:14:41Z GROOVY-7538 Resolve placeholder return types correctly ---- > Compiler crash in the static type checker with self-referencing generic type > ---------------------------------------------------------------------------- > > Key: GROOVY-7538 > URL: https://issues.apache.org/jira/browse/GROOVY-7538 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker > Affects Versions: 2.4.4 > Reporter: Frank Pavageau > Assignee: Cédric Champeau > Labels: test > > I'm writing unit tests in Groovy combined with AssertJ, and I got a compiler > crash with the following code: > {code} > Assertions.assertThat("true").isNotEmpty().isNotEqualTo("false") > {code} > The matching stacktrace is > {noformat} > java.lang.ArrayIndexOutOfBoundsException: 1 > at > org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders(GenericsUtils.java:167) > at > org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.extractPlaceHolders(StaticTypeCheckingVisitor.java:4455) > at > org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.resolvePlaceHoldersFromDeclaration(StaticTypeCheckingVisitor.java:4416) > at > org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferReturnTypeGenerics(StaticTypeCheckingVisitor.java:4206) > at > org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallExpression(StaticTypeCheckingVisitor.java:2924) > at > org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethodCallExpression(StaticCompilationVisitor.java:297) > at > org.codehaus.groovy.ast.expr.MethodCallExpression.visit(MethodCallExpression.java:66) > at > org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:71) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:196) > at > org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42) > at > org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:37) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:166) > at > org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:104) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:115) > at > org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:1773) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:126) > at > org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2106) > at > org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2065) > at > org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:163) > at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1086) > at > org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:53) > at > org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:249) > at > org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:122) > at > org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:63) > 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.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:192) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) > at > org.codehaus.groovy.control.customizers.ASTTransformationCustomizer.call(ASTTransformationCustomizer.groovy:294) > at > org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1055) > at > org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591) > at > org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569) > at > org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546) > ... > {noformat} > Also interesting is that if I swap the 2 assertions, the compiler doesn't > crash anymore, but I still get a compilation error from the static type > checker: > {code} > Assertions.assertThat("true").isNotEqualTo("false").isNotEmpty() > {code} > The error is then: > {noformat} > [Static type checking] - Cannot find matching method > org.assertj.core.api.AbstractAssert#isNotEmpty(). Please check if the > declared type is right and if the method exists. > {noformat} > Of course, both lines compile in Java. > I've created a test to reproduce the bugs, I'll create a pull request on > github right afterwards. -- This message was sent by Atlassian JIRA (v6.3.4#6332)