Skip to content

Commit c66b313

Browse files
Remove types as variables to allow user-defined variables to shadow type declarations (#1262)
1 parent bff3a72 commit c66b313

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

cel/library.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ func (lib *stdLibrary) CompileOptions() []EnvOption {
182182
if err = lib.subset.Validate(); err != nil {
183183
return nil, err
184184
}
185-
e.variables = append(e.variables, stdlib.Types()...)
186185
for _, fn := range funcs {
187186
existing, found := e.functions[fn.Name()]
188187
if found {

cel/testdata/standard_env.prompt.txt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ found in C++ or Java code.
1111

1212
Only use the following variables, macros, and functions in expressions.
1313

14-
Variables:
15-
16-
* bool is a type
17-
* bytes is a type
18-
* double is a type
19-
* google.protobuf.Duration is a type
20-
* google.protobuf.Timestamp is a type
21-
* int is a type
22-
* list is a type
23-
* map is a type
24-
* null_type is a type
25-
* string is a type
26-
* type is a type
27-
* uint is a type
28-
2914
Functions:
3015

3116
* !_ - logically negate a boolean value.

interpreter/interpreter_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,20 @@ func testData(t testing.TB) []testCase {
10411041
},
10421042
},
10431043
},
1044+
{
1045+
name: "type_dyn_equals_string",
1046+
expr: `type(dyn('')) == string`,
1047+
},
1048+
{
1049+
name: "type_override",
1050+
expr: `type == 'string'`,
1051+
vars: []*decls.VariableDecl{
1052+
decls.NewVariable("type", types.StringType),
1053+
},
1054+
in: map[string]any{
1055+
"type": "string",
1056+
},
1057+
},
10441058
{
10451059
name: "select_key",
10461060
expr: `m.strMap['val'] == 'string'

0 commit comments

Comments
 (0)