Name resolution and shadowing#
CEL identifiers are lexically scoped. Inner bindings shadow outer bindings with the same name.
Resolution order#
When CEL encounters an identifier, it checks in this order:
- Macro iteration variables
- Input variables
- Type names and enum values
Macro variables shadow input variables#
Macro iteration variables take precedence over input variables.
The macro variable x shadows the input variable x.
Nested macro shadowing#
In nested macros, inner variables shadow outer variables with the same name.
The inner x shadows the outer x, so each inner map returns [4, 5, 6].
Use unique, descriptive variable names to avoid confusion.
[1, 2, 3].map(outer,
[4, 5, 6].map(inner, outer + inner))
// result: [[5, 6, 7], [6, 7, 8], [7, 8, 9]] (list)