diff options
author | Wenchao Xia <wenchaoqemu@gmail.com> | 2014-03-04 18:44:39 -0800 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2014-03-11 09:07:42 -0400 |
commit | 5223070c47c6fc35ee000b2392ae76d9fab54f16 (patch) | |
tree | 52a971bbbc5db95b1ebaa064483eeb6ee54ecaeb /scripts/qapi.py | |
parent | 59ca664ef86c8a9078157336b566e832fc5466e2 (diff) |
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(): |