@@ -27,7 +27,7 @@ public static Map<String, Expression> resolve(Expression exp) {
2727 resolveRecursive (exp , map );
2828
2929 // remove variables that were not used in the expression
30- map .entrySet ().removeIf (entry -> !hasUsage (exp , entry .getKey (), entry .getValue ()));
30+ map .entrySet ().removeIf (entry -> !hasUsage (exp , entry .getKey (), entry .getValue (), true ));
3131
3232 // transitively resolve variables
3333 return resolveTransitive (map );
@@ -136,12 +136,14 @@ private static Expression lookup(Expression exp, Map<String, Expression> map, Se
136136 *
137137 * @param exp
138138 * @param name
139+ * @param value
140+ * @param canExcludeDefinition
139141 *
140142 * @return true if used, false otherwise
141143 */
142- private static boolean hasUsage (Expression exp , String name , Expression value ) {
144+ private static boolean hasUsage (Expression exp , String name , Expression value , boolean canExcludeDefinition ) {
143145 // exclude own definitions
144- if (exp instanceof BinaryExpression binary && "==" .equals (binary .getOperator ())) {
146+ if (canExcludeDefinition && exp instanceof BinaryExpression binary && "==" .equals (binary .getOperator ())) {
145147 Expression left = binary .getFirstOperand ();
146148 Expression right = binary .getSecondOperand ();
147149 if (left instanceof Var v && v .getName ().equals (name ) && right .equals (value )
@@ -167,8 +169,10 @@ && isConstant(left))
167169
168170 // recurse children
169171 if (exp .hasChildren ()) {
172+ boolean childCanExcludeDefinition = exp instanceof BinaryExpression binary
173+ && "&&" .equals (binary .getOperator ());
170174 for (Expression child : exp .getChildren ())
171- if (hasUsage (child , name , value ))
175+ if (hasUsage (child , name , value , childCanExcludeDefinition ))
172176 return true ;
173177 }
174178
0 commit comments