Skip to content

Commit 62f2758

Browse files
author
Markus Armbruster
committed
qapi: Fix bogus error for 'if': { 'not': '' }
Signed-off-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> [check_infix()'s type hint fixed]
1 parent 71f03ef commit 62f2758

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

scripts/qapi/expr.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,22 @@ def _check_if(cond: Union[str, object]) -> None:
293293
info,
294294
"'if' condition of %s has conflicting keys" % source)
295295

296-
oper, operands = next(iter(cond.items()))
296+
if 'not' in cond:
297+
_check_if(cond['not'])
298+
elif 'all' in cond:
299+
_check_infix('all', cond['all'])
300+
else:
301+
_check_infix('any', cond['any'])
302+
303+
def _check_infix(operator: str, operands: object) -> None:
304+
if not isinstance(operands, list):
305+
raise QAPISemError(
306+
info,
307+
"'%s' condition of %s must be an array"
308+
% (operator, source))
297309
if not operands:
298310
raise QAPISemError(
299311
info, "'if' condition [] of %s is useless" % source)
300-
301-
if oper == "not":
302-
_check_if(operands)
303-
return
304-
if oper in ("all", "any") and not isinstance(operands, list):
305-
raise QAPISemError(
306-
info, "'%s' condition of %s must be an array" % (oper, source))
307312
for operand in operands:
308313
_check_if(operand)
309314

tests/qapi-schema/bad-if-not.err

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
bad-if-not.json: In struct 'TestIfStruct':
2-
bad-if-not.json:2: 'if' condition [] of struct is useless
2+
bad-if-not.json:2: 'if' condition '' of struct is not a valid identifier

0 commit comments

Comments
 (0)