You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/11/08 18:31:20 UTC

[groovy] branch master updated: GROOVY-10353: `evaluateExpression` short-circuit for primitives and null

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new cb8f8f8796 GROOVY-10353: `evaluateExpression` short-circuit for primitives and null
cb8f8f8796 is described below

commit cb8f8f87966835b57f3acbc877a2252907aed0f4
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Nov 8 11:39:50 2022 -0600

    GROOVY-10353: `evaluateExpression` short-circuit for primitives and null
---
 .../codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 037a458a19..9d4af3f7fc 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -2206,10 +2206,10 @@ public abstract class StaticTypeCheckingSupport {
     public static Object evaluateExpression(final Expression expr, final CompilerConfiguration config, /*@Nullable*/ final GroovyClassLoader loader) {
         Expression ce = expr instanceof CastExpression ? ((CastExpression) expr).getExpression() : expr;
         if (ce instanceof ConstantExpression) {
-            if (expr.getType().equals(ce.getType()))
-                return ((ConstantExpression) ce).getValue();
+            if (expr.getType().equals(getWrapper(ce.getType())) || ((ConstantExpression) ce).isNullExpression())
+                return ((ConstantExpression) ce).getValue(); // boolean, number, string, or null
         } else if (ce instanceof ListExpression) {
-            if (expr.getType().isArray() && expr.getType().getComponentType().equals(STRING_TYPE))
+            if (expr.getType().isArray() && isStringType(expr.getType().getComponentType()))
                 return ((ListExpression) ce).getExpressions().stream().map(e -> evaluateExpression(e, config, loader)).toArray(String[]::new);
         }