Skip to content

Commit

Permalink
Make sure expression type does not change after processing with rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sopel39 authored and wendigo committed Jun 14, 2024
1 parent 5e2f4bb commit de6ba02
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
import java.util.Map;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkState;

public class IrExpressionOptimizer
{
private final List<IrOptimizerRule> rules;
Expand Down Expand Up @@ -286,6 +288,12 @@ private Optional<Expression> applyRules(Expression expression, Session session,
for (IrOptimizerRule rule : rules) {
Optional<Expression> optimized = rule.apply(expression, session, bindings);
if (optimized.isPresent()) {
checkState(
expression.type().equals(optimized.get().type()),
"Rule %s changed expression type from %s to %s",
rule.getClass().getSimpleName(),
expression.type(),
optimized.get().type());
expression = optimized.get();
changed = true;
}
Expand Down

0 comments on commit de6ba02

Please sign in to comment.