From a6299f8401fa5fcdc504380899518c5a4870a12c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 11 Jan 2022 17:24:17 +0100 Subject: [PATCH] Use a proper condition check when dealing with flag vectors When reading flag vectors, non-existent vectors are being translated to [] (empty list). When writing them, the flag condition was strictly checking for None and an empty list [] would result in an empty vector being serialized, which should not happen. Related to #871. --- compiler/api/compiler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 192d6a67..150fa49d 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -408,7 +408,7 @@ def start(format: bool = False): flag = FLAGS_RE_2.match(i[1]) if flag: - if flag.group(2) == "true": + if flag.group(2) == "true" or flag.group(2).startswith("Vector"): write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} else 0") else: write_flags.append(f"flags |= (1 << {flag.group(1)}) if self.{i[0]} is not None else 0") @@ -441,7 +441,7 @@ def start(format: bool = False): sub_type = arg_type.split("<")[1][:-1] write_types += "\n " - write_types += f"if self.{arg_name} is not None:\n " + write_types += f"if self.{arg_name}:\n " write_types += "b.write(Vector(self.{}{}))\n ".format( arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "" )