qapi: Fix bogus error for 'if': { 'not': '' }
authorMarkus Armbruster <armbru@redhat.com>
Wed, 8 Sep 2021 04:54:28 +0000 (06:54 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Wed, 8 Sep 2021 13:30:30 +0000 (15:30 +0200)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210908045428.2689093-6-armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
[check_infix()'s type hint fixed]

scripts/qapi/expr.py
tests/qapi-schema/bad-if-not.err

index b62f0a3640632e474e3562823126f661f5696836..90bde501b02357ab4cd3c866be5339699f7ec9af 100644 (file)
@@ -293,17 +293,22 @@ def check_if(expr: _JSONObject, info: QAPISourceInfo, source: str) -> None:
                 info,
                 "'if' condition of %s has conflicting keys" % source)
 
-        oper, operands = next(iter(cond.items()))
+        if 'not' in cond:
+            _check_if(cond['not'])
+        elif 'all' in cond:
+            _check_infix('all', cond['all'])
+        else:
+            _check_infix('any', cond['any'])
+
+    def _check_infix(operator: str, operands: object) -> None:
+        if not isinstance(operands, list):
+            raise QAPISemError(
+                info,
+                "'%s' condition of %s must be an array"
+                % (operator, source))
         if not operands:
             raise QAPISemError(
                 info, "'if' condition [] of %s is useless" % source)
-
-        if oper == "not":
-            _check_if(operands)
-            return
-        if oper in ("all", "any") and not isinstance(operands, list):
-            raise QAPISemError(
-                info, "'%s' condition of %s must be an array" % (oper, source))
         for operand in operands:
             _check_if(operand)
 
index b3acdd679af662705f669859b5765e377cb094d1..b33f5e16b8056bd3ef00a473b9b93844232ad79f 100644 (file)
@@ -1,2 +1,2 @@
 bad-if-not.json: In struct 'TestIfStruct':
-bad-if-not.json:2: 'if' condition [] of struct is useless
+bad-if-not.json:2: 'if' condition '' of struct is not a valid identifier