@@ -26,7 +26,7 @@ public static Map<String, Expression> resolve(Expression exp) {
2626 resolveRecursive (exp , map );
2727
2828 // remove variables that were not used in the expression
29- map .entrySet ().removeIf (entry -> !hasUsage (exp , entry .getKey ()));
29+ map .entrySet ().removeIf (entry -> !hasUsage (exp , entry .getKey (), entry . getValue () ));
3030
3131 // transitively resolve variables
3232 return resolveTransitive (map );
@@ -138,20 +138,21 @@ private static Expression lookup(Expression exp, Map<String, Expression> map, Se
138138 *
139139 * @return true if used, false otherwise
140140 */
141- private static boolean hasUsage (Expression exp , String name ) {
141+ private static boolean hasUsage (Expression exp , String name , Expression value ) {
142142 // exclude own definitions
143143 if (exp instanceof BinaryExpression binary && "==" .equals (binary .getOperator ())) {
144144 Expression left = binary .getFirstOperand ();
145145 Expression right = binary .getSecondOperand ();
146- if (left instanceof Var v && v .getName ().equals (name )
146+ if (left instanceof Var v && v .getName ().equals (name ) && right . equals ( value )
147147 && (right .isLiteral () || (!(right instanceof Var ) && canSubstitute (v , right ))))
148148 return false ;
149- if (left instanceof FunctionInvocation && left .toString ().equals (name )
149+ if (left instanceof FunctionInvocation && left .toString ().equals (name ) && right . equals ( value )
150150 && (right .isLiteral () || (!(right instanceof Var ) && !containsExpression (right , left ))))
151151 return false ;
152- if (right instanceof Var v && v .getName ().equals (name ) && left .isLiteral ())
152+ if (right instanceof Var v && v .getName ().equals (name ) && left .equals ( value ) && left . isLiteral ())
153153 return false ;
154- if (right instanceof FunctionInvocation && right .toString ().equals (name ) && left .isLiteral ())
154+ if (right instanceof FunctionInvocation && right .toString ().equals (name ) && left .equals (value )
155+ && left .isLiteral ())
155156 return false ;
156157 }
157158
@@ -166,7 +167,7 @@ private static boolean hasUsage(Expression exp, String name) {
166167 // recurse children
167168 if (exp .hasChildren ()) {
168169 for (Expression child : exp .getChildren ())
169- if (hasUsage (child , name ))
170+ if (hasUsage (child , name , value ))
170171 return true ;
171172 }
172173
0 commit comments