groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] branch GROOVY-7996 updated: Exclude closure parameter references from dynamic resolution
Date Tue, 05 Nov 2019 23:20:35 GMT
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-7996
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY-7996 by this push:
     new bed7f93  Exclude closure parameter references from dynamic resolution
bed7f93 is described below

commit bed7f9312533d0c5c7209b9ff9e8dc1f07a5fcb0
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Tue Nov 5 17:20:29 2019 -0600

    Exclude closure parameter references from dynamic resolution
---
 src/main/java/org/codehaus/groovy/ast/tools/ClosureUtils.java     | 8 +++++++-
 .../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java  | 4 +++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/tools/ClosureUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/ClosureUtils.java
index da07990..16db26d 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/ClosureUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/ClosureUtils.java
@@ -21,11 +21,14 @@ package org.codehaus.groovy.ast.tools;
 import groovy.lang.Closure;
 import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.expr.ClosureExpression;
+import org.codehaus.groovy.ast.expr.VariableExpression;
 import org.codehaus.groovy.control.io.ReaderSource;
+
+import java.util.Arrays;
+
 /**
  * Handy methods when working with Closure AST data structures.
  */
-
 public class ClosureUtils {
 
     /**
@@ -81,4 +84,7 @@ public class ClosureUtils {
         return ce.getParameters() != null ? ce.getParameters() : Parameter.EMPTY_ARRAY;
     }
 
+    public static boolean isParameterReference(VariableExpression ve, ClosureExpression ce)
{
+        return Arrays.asList(getParametersSafe(ce)).contains(ve.getAccessedVariable());
+    }
 }
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 3e562e2..9ea7130 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -180,6 +180,7 @@ import static org.codehaus.groovy.ast.ClassHelper.long_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.short_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.void_WRAPPER_TYPE;
 import static org.codehaus.groovy.ast.tools.ClosureUtils.getParametersSafe;
+import static org.codehaus.groovy.ast.tools.ClosureUtils.isParameterReference;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.binX;
 import static org.codehaus.groovy.ast.tools.GeneralUtils.block;
@@ -1719,7 +1720,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
 
             // GROOVY-7996: check if receiver implements get(String)/set(String,Object) or
propertyMissing(String)
             if (!testClass.isArray() && !isPrimitiveType(getUnwrapper(testClass))
-                    && objectExpression instanceof VariableExpression &&
typeCheckingContext.getEnclosingClosure() != null) {
+                    && objectExpression instanceof VariableExpression &&
typeCheckingContext.getEnclosingClosure() != null
+                    && !isParameterReference((VariableExpression) objectExpression,
typeCheckingContext.getEnclosingClosure().getClosureExpression())) {
                 MethodNode mopMethod;
                 if (readMode) {
                     mopMethod = testClass.getMethod("get", new Parameter[]{new Parameter(STRING_TYPE,
"name")});


Mime
View raw message