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:07:51 UTC
[2/2] groovy git commit: GROOVY-8249: Newify local variable
declaration fails to resolve class expression (closes #584)
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/671b4fe4
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/671b4fe4
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/671b4fe4
Branch: refs/heads/GROOVY_2_5_X
Commit: 671b4fe4a72ba18210d18cfc014c45a1ff25b73d
Parents: a6bbacf
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:07:38 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/671b4fe4/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 9085eb7..1801e5e 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/671b4fe4/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