Skip to content

Commit

Permalink
Short-circuit in optional.or and optional.orValue when receiver i…
Browse files Browse the repository at this point in the history
…s unknown

PiperOrigin-RevId: 626441848
  • Loading branch information
jcking authored and copybara-github committed Apr 22, 2024
1 parent 10e9700 commit 45ae229
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions eval/eval/jump_step.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ class OptionalHasValueJumpStep final : public JumpStepBase {
const auto& value = frame->value_stack().Peek();
auto optional_value = cel::As<cel::OptionalValue>(value);
// We jump if the receiver is `optional_type` which has a value or the
// receiver is an error. Unlike `_||_` we are not commutative. If we run
// into an error, we skip the `else` branch.
// receiver is an error/unknown. Unlike `_||_` we are not commutative. If
// we run into an error/unknown, we skip the `else` branch.
const bool should_jump =
(optional_value.has_value() && optional_value->HasValue()) ||
(!optional_value.has_value() &&
cel::InstanceOf<cel::ErrorValue>(value));
(cel::InstanceOf<cel::ErrorValue>(value) ||
cel::InstanceOf<cel::UnknownValue>(value)));
if (should_jump) {
if (or_value_ && optional_value.has_value()) {
frame->value_stack().PopAndPush(optional_value->Value());
Expand Down

0 comments on commit 45ae229

Please # to comment.