Skip to content

Commit 79cc320

Browse files
l46kokcopybara-github
authored andcommitted
Fix dead code reachability logic erroneously flagging on unconditional nested rules
Port of https://github.com/google/cel-go/pull/1323 PiperOrigin-RevId: 924956895
1 parent e4c38de commit 79cc320

9 files changed

Lines changed: 246 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: nested_rules_variable_shadowing
16+
variables:
17+
- name: x
18+
type_name: int
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: nested_rules_variable_shadowing
16+
rule:
17+
variables:
18+
- name: i
19+
expression: '1'
20+
- name: j
21+
expression: '2'
22+
match:
23+
- condition: "x == 1"
24+
rule:
25+
variables:
26+
- name: i
27+
expression: "5"
28+
match:
29+
- output: "variables.i + variables.j"
30+
- condition: "x == 2"
31+
rule:
32+
match:
33+
- output: "variables.i + variables.j"
34+
- output: "variables.i + variables.j"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
description: "Nested rule tests for rule variable shadowing"
16+
section:
17+
- name: "shadowing"
18+
tests:
19+
- name: "shadowed"
20+
input:
21+
x:
22+
expr: "1"
23+
output:
24+
expr: "7"
25+
- name: "neighbor_rule"
26+
input:
27+
x:
28+
expr: "2"
29+
output:
30+
expr: "3"
31+
- name: "parent_rule"
32+
input:
33+
x:
34+
expr: "3"
35+
output:
36+
expr: "3"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: unconditional_rules
2+
variables:
3+
- name: a
4+
type_name: bool
5+
- name: b
6+
type_name: bool
7+
- name: c
8+
type_name: bool
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: unconditional_rules
16+
rule:
17+
match:
18+
- condition: "a"
19+
rule:
20+
match:
21+
- rule:
22+
match:
23+
- condition: "b"
24+
output: "1"
25+
- output: "2"
26+
- rule:
27+
match:
28+
- condition: "c"
29+
output: "3"
30+
- output: "4"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
description: Unconditional rules propagation conformance tests
16+
section:
17+
- name: "composition"
18+
tests:
19+
- name: "case_a_true_b_true"
20+
input:
21+
a:
22+
expr: "true"
23+
b:
24+
expr: "true"
25+
c:
26+
expr: "true"
27+
output:
28+
expr: "1"
29+
- name: "case_a_true_b_false"
30+
input:
31+
a:
32+
expr: "true"
33+
b:
34+
expr: "false"
35+
c:
36+
expr: "true"
37+
output:
38+
expr: "2"
39+
- name: "case_a_false_c_true"
40+
input:
41+
a:
42+
expr: "false"
43+
b:
44+
expr: "false"
45+
c:
46+
expr: "true"
47+
output:
48+
expr: "3"
49+
- name: "case_a_false_c_false"
50+
input:
51+
a:
52+
expr: "false"
53+
b:
54+
expr: "false"
55+
c:
56+
expr: "false"
57+
output:
58+
expr: "4"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: variable_type_propagation
16+
variables:
17+
- name: x
18+
type_name: int
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: variable_type_propagation
16+
rule:
17+
variables:
18+
- name: empty_list
19+
expression: '[]'
20+
- name: string_list
21+
expression: '["foo"]'
22+
match:
23+
- output: "variables.empty_list + [1]"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
description: "Rule demonstrating variable types propagate independently"
16+
section:
17+
- name: "test"
18+
tests:
19+
- name: "types_agree"
20+
output:
21+
expr: "[1]"

0 commit comments

Comments
 (0)