groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [1/2] groovy git commit: GROOVY-8249: Newify local variable declaration fails to resolve class expression (closes #584)
Date Wed, 27 Sep 2017 08:07:20 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 10e0fd9b7 -> 4c10ed516


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/4c10ed51
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4c10ed51
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4c10ed51

Branch: refs/heads/GROOVY_2_6_X
Commit: 4c10ed51654f73c1f3a16a5a5090c836c9067aa3
Parents: 639896b
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Sun Aug 13 17:15:00 2017 -0700
Committer: paulk <paulk@asert.com.au>
Committed: Wed Sep 27 18:07:08 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/4c10ed51/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/4c10ed51/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


Mime
View raw message