diff options
author | Wenchao Xia | 2014-03-05 03:44:39 +0100 |
---|---|---|
committer | Luiz Capitulino | 2014-03-11 14:07:42 +0100 |
commit | 5223070c47c6fc35ee000b2392ae76d9fab54f16 (patch) | |
tree | 52a971bbbc5db95b1ebaa064483eeb6ee54ecaeb /scripts/qapi.py | |
parent | qapi: convert BlockdevOptions to use enum discriminator (diff) | |
download | qemu-5223070c47c6fc35ee000b2392ae76d9fab54f16.tar.gz qemu-5223070c47c6fc35ee000b2392ae76d9fab54f16.tar.xz qemu-5223070c47c6fc35ee000b2392ae76d9fab54f16.zip |
qapi script: do not allow string discriminator
Since enum based discriminators provide better type-safety and
ensure that future qapi additions do not forget to adjust dependent
unions, forbid using string as discriminator from now on.
Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'scripts/qapi.py')
-rw-r--r-- | scripts/qapi.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py index 2b43ad2f1b..bd00d01c0f 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -239,6 +239,11 @@ def check_union(expr, expr_info): "type '%s'" % (discriminator, base)) enum_define = find_enum(discriminator_type) + # Do not allow string discriminator + if not enum_define: + raise QAPIExprError(expr_info, + "Discriminator '%s' must be of enumeration " + "type" % discriminator) # Check every branch for (key, value) in members.items(): |