Skip to content

fix(expression): treat constants as neutral in IsBoundVisitor - #1004

Merged
wgtmac merged 1 commit into
apache:mainfrom
YinZheng-Sun:fix/is-bound-visitor-constants
Oct 13, 2026
Merged

wgtmac merged 1 commit into
apache:mainfrom
YinZheng-Sun:fix/is-bound-visitor-constants

Conversation

@YinZheng-Sun

Copy link
Copy Markdown
Contributor

What

IsBoundVisitor previously returned an error for AlwaysTrue/AlwaysFalse,
so any expression tree that still contained a constant (e.g. built via
And::Make / Or::Make without folding) could not be checked.

This PR changes the visitor's internal result type to std::optional<bool>:

  • std::nullopt means the subtree contains no references (True/False),
    so constants are neutral when combining binding states:
    And(True, unbound) is unbound and And(True, bound) is bound.
  • Mixing bound and unbound predicates is now rejected with
    Found partially bound expression instead of silently returning false.
  • The public IsBoundVisitor::IsBound() API still returns a definite bool
    (an expression with only constants is reported as not bound).

This follows Java's IsBoundVisitor.

Why

Split out from #956

Tests

  • Updated IsBoundVisitorTest for constants and mixed binding states.
  • Added AndWithConstants / OrWithConstants cases.

AlwaysTrue/AlwaysFalse no longer make IsBoundVisitor fail. Constants contain no references and are now neutral when combining binding states, so And(True, unbound) is unbound and And(True, bound) is bound. Mixing bound and unbound predicates is rejected with an error. This follows Java's IsBoundVisitor.
@wgtmac
wgtmac merged commit f799dcb into apache:main Oct 13, 2026
15 checks passed
@wgtmac

wgtmac commented Oct 13, 2026

Copy link
Copy Markdown
Member

Thanks for separating a smaller PR! @YinZheng-Sun

@YinZheng-Sun
YinZheng-Sun deleted the fix/is-bound-visitor-constants branch October 13, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants