Skip to content

Limit unary minus to the declared numeric types - #1673

Open
powerman2026 wants to merge 2 commits into
cel-expr:masterfrom
powerman2026:fix/dynamic-unary-minus
Open

powerman2026 wants to merge 2 commits into
cel-expr:masterfrom
powerman2026:fix/dynamic-unary-minus

Conversation

@powerman2026

Copy link
Copy Markdown

Fixes #1646.

The checker allows unary minus for int and double. The interpreter dispatched it through the negation trait, which duration also implements. As a result, changing a duration expression's static type to dyn could change a type error into a valid negative duration.

Check the CEL type before calling the trait implementation. The interpreter table covers dynamic duration and bool rejection and successful int and double negation across its evaluation modes.

On master the new duration case returned -1s instead of an overload error. The targeted tests and go test -race ./... pass with the change.

Duration and bool implement the same negation trait as int and double.
Check the runtime CEL type so dynamic inputs follow the declarations.
@google-cla

google-cla Bot commented Nov 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

Unary minus negates a duration when the operand type is dynamic

1 participant