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:57:58 UTC

[groovy] branch GROOVY_3_0_X 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 GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


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

commit 0c106c9b54e87f7dd4d0e9a0a972e8dc8c8d128e
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Nov 8 12:43:10 2022 -0600

    GROOVY-10353: `evaluateExpression` short-circuit for primitives and null
---
 .../org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 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 9d6f028ba9..a09d9ede3e 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -2170,8 +2170,8 @@ 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))
                 return ((ListExpression) ce).getExpressions().stream().map(e -> evaluateExpression(e, config, loader)).toArray(String[]::new);