From 7308f9d5a4da8ea4e2a9a0748ceb0921333c11f4 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 11 Sep 2024 16:04:43 +0200 Subject: 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. --- sys/test/expressions.txt | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'sys/test') 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 -- cgit mrf-deployment