You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/09/27 08:06:30 UTC
groovy git commit: GROOVY-8249: Newify local variable declaration
fails to resolve class expression (closes #584)
Repository: groovy
Updated Branches:
refs/heads/master d99246ffd -> 8b99a30e0
GROOVY-8249: Newify local variable declaration fails to resolve class expression (closes #584)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8b99a30e
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8b99a30e
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8b99a30e
Branch: refs/heads/master
Commit: 8b99a30e0fc045ef652bf03ad8a30fc904c2c43e
Parents: d99246f
Author: John Wagenleitner <jw...@apache.org>
Authored: Sun Aug 13 17:15:00 2017 -0700
Committer: paulk <pa...@asert.com.au>
Committed: Wed Sep 27 18:05:53 2017 +1000
----------------------------------------------------------------------
.../groovy/classgen/VariableScopeVisitor.java | 3 +--
.../groovy/transform/NewifyTransformTest.groovy | 24 ++++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/8b99a30e/src/main/org/codehaus/groovy/classgen/VariableScopeVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/VariableScopeVisitor.java b/src/main/org/codehaus/groovy/classgen/VariableScopeVisitor.java
index 7a99014..3ae14b6 100644
--- a/src/main/org/codehaus/groovy/classgen/VariableScopeVisitor.java
+++ b/src/main/org/codehaus/groovy/classgen/VariableScopeVisitor.java
@@ -38,8 +38,6 @@ import static java.lang.reflect.Modifier.isFinal;
/**
* goes through an AST and initializes the scopes
- *
- * @author Jochen Theodorou
*/
public class VariableScopeVisitor extends ClassCodeVisitorSupport {
@@ -330,6 +328,7 @@ public class VariableScopeVisitor extends ClassCodeVisitorSupport {
}
public void visitDeclarationExpression(DeclarationExpression expression) {
+ visitAnnotations(expression);
// visit right side first to avoid the usage of a
// variable before its declaration
expression.getRightExpression().visit(this);
http://git-wip-us.apache.org/repos/asf/groovy/blob/8b99a30e/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy b/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy
index d585c8a..c2cce48 100644
--- a/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/NewifyTransformTest.groovy
@@ -211,4 +211,28 @@ class NewifyTransformTest extends GroovyShellTestCase {
assert Foo.answer == 42
'''
}
+
+ // GROOVY-8249
+ void testLocalVariableDeclResolvesClass() {
+ assertScript '''
+ class A {
+ final int id
+ A(int id) { this.id = id + 10 }
+ }
+ class Foo {
+ static String test() {
+ @Newify(String)
+ String answer = String('bar')
+ answer
+ }
+ static int test2() {
+ @Newify(A)
+ int answer = A(32).id
+ answer
+ }
+ }
+ assert Foo.test() == 'bar'
+ assert Foo.test2() == 42
+ '''
+ }
}
\ No newline at end of file