Repository: groovy Updated Branches: refs/heads/native-lambda 7e3459347 -> 621cd4a4c
Fix lambda in constructor Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/621cd4a4 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/621cd4a4 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/621cd4a4 Branch: refs/heads/native-lambda Commit: 621cd4a4c710fc6da9045e824f904d480705a05b Parents: 7e34593 Author: sunlan <[email protected]> Authored: Thu Jan 18 18:18:56 2018 +0800 Committer: sunlan <[email protected]> Committed: Thu Jan 18 18:20:30 2018 +0800 ---------------------------------------------------------------------- .../asm/sc/StaticTypesLambdaWriter.java | 3 ++- src/test/groovy/transform/stc/LambdaTest.groovy | 23 ++++++++++++++++++++ .../parser/antlr4/GroovyParserTest.groovy | 5 +---- 3 files changed, 26 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/621cd4a4/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java index f30fbc2..78848be 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java @@ -130,8 +130,9 @@ public class StaticTypesLambdaWriter extends LambdaWriter { private void loadEnclosingClassInstance() { MethodVisitor mv = controller.getMethodVisitor(); OperandStack operandStack = controller.getOperandStack(); + CompileStack compileStack = controller.getCompileStack(); - if (controller.getMethodNode().isStatic()) { + if (controller.isStaticMethod() || compileStack.isInSpecialConstructorCall()) { operandStack.pushConstant(ConstantExpression.NULL); } else { mv.visitVarInsn(ALOAD, 0); http://git-wip-us.apache.org/repos/asf/groovy/blob/621cd4a4/src/test/groovy/transform/stc/LambdaTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy index 31d0060..356dffa 100644 --- a/src/test/groovy/transform/stc/LambdaTest.groovy +++ b/src/test/groovy/transform/stc/LambdaTest.groovy @@ -333,6 +333,29 @@ TestScript0.groovy: 14: [Static type checking] - Cannot find matching method jav ''' } + void testFunctionInConstructor() { + assertScript ''' + import groovy.transform.CompileStatic + import java.util.stream.Collectors + import java.util.stream.Stream + + @CompileStatic + public class Test4 { + public static void main(String[] args) { + new Test4(); + } + + public Test4() { + assert ['Hello Jochen', 'Hello Daniel'] == Stream.of("Jochen", "Daniel").map(e -> hello() + e).collect(Collectors.toList()); + } + + public String hello() { + return "Hello "; + } + } + ''' + } + void testFunctionWithInstanceMethodCall2() { assertScript ''' import groovy.transform.CompileStatic http://git-wip-us.apache.org/repos/asf/groovy/blob/621cd4a4/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy index cbc3a20..9b58e97 100644 --- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy +++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy @@ -141,11 +141,9 @@ class GroovyParserTest extends GroovyTestCase { doTest('core/Closure_10.groovy', [Parameter]) } - /* TODO uncomment void "test groovy core - Lambda"() { doRunAndTestAntlr4('core/Lambda_01x.groovy') } - */ void "test groovy core - MethodReference"() { doRunAndTestAntlr4('core/MethodReference_01x.groovy') @@ -384,8 +382,7 @@ class GroovyParserTest extends GroovyTestCase { doRunAndTestAntlr4('bugs/GROOVY-3898.groovy') doRunAndTestAntlr4('bugs/BUG-GROOVY-8311.groovy') - // TODO uncomment - // doRunAndTestAntlr4('bugs/GROOVY-8228.groovy') + doRunAndTestAntlr4('bugs/GROOVY-8228.groovy') doRunAndTest('bugs/BUG-GROOVY-8426.groovy') }
