aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2016-02-17 23:48:17 -0700
committerMarkus Armbruster <armbru@redhat.com>2016-02-19 11:08:56 +0100
commit46534309e667fd860720f983c2c9aefe0354340d (patch)
treedef73f0f34e3c1fd607c2624d350312e2a0a0791 /scripts
parent02a57ae32b08e8981b59979b80e682c9a153e94d (diff)
downloadqemu-46534309e667fd860720f983c2c9aefe0354340d.zip
qemu-46534309e667fd860720f983c2c9aefe0354340d.tar.gz
qemu-46534309e667fd860720f983c2c9aefe0354340d.tar.bz2
qapi: Forbid 'any' inside an alternate
The whole point of an alternate is to allow some type-safety while still accepting more than one JSON type. Meanwhile, the 'any' type exists to bypass type-safety altogether. The two are incompatible: you can't accept every type, and still tell which branch of the alternate to use for the parse; fix this to give a sane error instead of a Python stack trace. Note that other types that can't be alternate members are caught earlier, by check_type(). Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1455778109-6278-4-git-send-email-eblake@redhat.com> [Commit message tweaked] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index f97236f..17bf633 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -629,7 +629,10 @@ def check_alternate(expr, expr_info):
value,
allow_metas=['built-in', 'union', 'struct', 'enum'])
qtype = find_alternate_member_qtype(value)
- assert qtype
+ if not qtype:
+ raise QAPIExprError(expr_info,
+ "Alternate '%s' member '%s' cannot use "
+ "type '%s'" % (name, key, value))
if qtype in types_seen:
raise QAPIExprError(expr_info,
"Alternate '%s' member '%s' can't "