aboutsummaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2024-09-11 16:04:43 +0200
committerAleksandr Nogikh <nogikh@google.com>2024-09-11 14:55:22 +0000
commit7308f9d5a4da8ea4e2a9a0748ceb0921333c11f4 (patch)
tree3c4c0d6bdfd082e089a5514c0c06e7eabec864f9 /sys
parentfd0ad8a3f899365059471f5fdefdc73082ce0777 (diff)
prog: allow deeper nesting of conditional fields patching
There is a totally valid situation when we could be recursively patching conditional fields: if by changing a field's value we insert new resource constructor calls. It's a bug to skip conditional field patching for them. Allow up to 2 nested patchConditionalFields() calls and panic if there happen to be more. Add a test that reproduces the situation described above.
Diffstat (limited to 'sys')
-rw-r--r--sys/test/expressions.txt23
1 files changed, 22 insertions, 1 deletions
diff --git a/sys/test/expressions.txt b/sys/test/expressions.txt
index 1c1cfbca5..500bdec20 100644
--- a/sys/test/expressions.txt
+++ b/sys/test/expressions.txt
@@ -16,7 +16,28 @@ conditional_struct {
f2 int64 (if[value[mask] & FIELD_FLAG2])
} [packed]
-test$conditional_struct(a ptr[in, conditional_struct])
+resource some_res[int32]
+
+test$conditional_struct(a ptr[in, conditional_struct]) some_res
+
+# To generate this call, we need to recursively also generate a test$conditional_struct() call.
+
+needs_some_res {
+ switch int32
+ field some_res (if[value[switch] != 0])
+}
+
+resource some_res_nested[int32]
+test$conditional_struct_nested(a ptr[in, needs_some_res]) some_res_nested
+
+# .. and one more level.
+
+needs_some_res_nested {
+ switch int32
+ field some_res_nested (if[value[switch] != 0])
+}
+
+test$conditional_struct_nested2(a ptr[in, needs_some_res_nested])
parent_conditions {
mask int32