Skip to content

Commit

Permalink
fold const
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Nov 29, 2024
1 parent 97bd558 commit dfa39da
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,12 @@ public Expression visitAnd(And and, ExpressionRewriteContext context) {
return and.withChildren(nonTrueLiteral);
}
} else if (nullCount < and.children().size()) {
// null and x
return and.withChildren(nonTrueLiteral);
if (nonTrueLiteral.size() == 1) {
return nonTrueLiteral.get(0);
} else {
// null and x
return and.withChildren(nonTrueLiteral);
}
} else {
// null and null and null and ...
return new NullLiteral(BooleanType.INSTANCE);
Expand Down Expand Up @@ -438,10 +442,10 @@ public Expression visitOr(Or or, ExpressionRewriteContext context) {
// x or y
return or.withChildren(nonFalseLiteral);
}
} else if (nullCount == 1) {
} else if (nullCount < nonFalseLiteral.size()) {
if (nonFalseLiteral.size() == 1) {
// null or false
return new NullLiteral(BooleanType.INSTANCE);
return nonFalseLiteral.get(0);
}
// null or x
return or.withChildren(nonFalseLiteral);
Expand Down

0 comments on commit dfa39da

Please sign in to comment.