Skip to content

Commit 5851044

Browse files
Fix _%_ FunctionDecl: only add cross-type overload, not standard ones
Adding standard overloads (int/int, uint/uint) collides with built-ins (modulo_int64, modulo_uint64). Adding only the cross-type (int/uint) overload succeeds because it's a novel parameter combination. The result is uint64 so "this % 2u == 0u" works with the built-in _==_(uint64, uint64).
1 parent b3bf39a commit 5851044

1 file changed

Lines changed: 4 additions & 18 deletions

File tree

protovalidate/internal/extra_func.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,27 +1780,13 @@ def make_extra_funcs() -> cel.CelExtension:
17801780
),
17811781
# Cross-type int/uint modulo overload.
17821782
# CEL predefined rules for uint types use uint literals (e.g. "this % 2u == 0u"),
1783-
# but Python int values are mapped to CEL int64. The result is uint64 so that
1784-
# the subsequent "== 0u" comparison uses the built-in _==_(uint64, uint64).
1785-
# Operator FunctionDecls replace the built-in, so all standard overloads must
1786-
# be included here alongside the cross-type overload.
1783+
# but Python int values are mapped to CEL int64. This overload bridges the gap:
1784+
# int64 % uint64 → uint64, so the subsequent "== 0u" comparison uses the
1785+
# built-in _==_(uint64, uint64). Adding a new overload with a novel parameter
1786+
# combination does not collide with the existing built-ins.
17871787
cel.FunctionDecl(
17881788
"_%_",
17891789
[
1790-
cel.Overload(
1791-
"_mod__int_int",
1792-
return_type=cel.Type.INT,
1793-
parameters=[cel.Type.INT, cel.Type.INT],
1794-
is_member=False,
1795-
impl=lambda a, b: a % b,
1796-
),
1797-
cel.Overload(
1798-
"_mod__uint_uint",
1799-
return_type=cel.Type.UINT,
1800-
parameters=[cel.Type.UINT, cel.Type.UINT],
1801-
is_member=False,
1802-
impl=lambda a, b: a % b,
1803-
),
18041790
cel.Overload(
18051791
"_mod__int_uint",
18061792
return_type=cel.Type.UINT,

0 commit comments

Comments
 (0)