GROOVY-8600: BUG! exception in phase 'instruction selection'
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c2790b4d Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c2790b4d Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c2790b4d Branch: refs/heads/GROOVY_2_6_X Commit: c2790b4dfdfa8320050eb0de794ebf6998ead3f0 Parents: 6abaa15 Author: Paul King <[email protected]> Authored: Thu May 24 00:07:10 2018 +1000 Committer: Paul King <[email protected]> Committed: Thu May 24 00:09:19 2018 +1000 ---------------------------------------------------------------------- .../MethodCallExpressionTransformer.java | 2 +- src/test/groovy/bugs/Groovy8600Bug.groovy | 37 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/c2790b4d/src/main/java/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java b/src/main/java/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java index c93db9e..5dd83ad 100644 --- a/src/main/java/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java +++ b/src/main/java/org/codehaus/groovy/transform/sc/transformers/MethodCallExpressionTransformer.java @@ -61,7 +61,7 @@ public class MethodCallExpressionTransformer { } Expression objectExpression = expr.getObjectExpression(); ClassNode type = staticCompilationTransformer.getTypeChooser().resolveType(objectExpression, staticCompilationTransformer.getClassNode()); - if (isCallOnClosure(expr)) { + if (isCallOnClosure(expr) && staticCompilationTransformer.getClassNode() != null) { FieldNode field = staticCompilationTransformer.getClassNode().getField(expr.getMethodAsString()); if (field != null) { VariableExpression vexp = new VariableExpression(field); http://git-wip-us.apache.org/repos/asf/groovy/blob/c2790b4d/src/test/groovy/bugs/Groovy8600Bug.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/bugs/Groovy8600Bug.groovy b/src/test/groovy/bugs/Groovy8600Bug.groovy new file mode 100644 index 0000000..43d4093 --- /dev/null +++ b/src/test/groovy/bugs/Groovy8600Bug.groovy @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package groovy.bugs + +class Groovy8600Bug extends GroovyTestCase { + void testClosureFieldUseWithinMethod() { + assertScript ''' + import groovy.transform.CompileStatic + + class TestCompileStatic { + private Closure<String> func = { it.toUpperCase() } + @CompileStatic + def testCallFunc () { + func('foo') + func.call('bar') + } + } + + assert new TestCompileStatic().testCallFunc() == 'FOOBAR' + ''' + } +}
