From f03255362ae3bfd6f105c0fc855c713944f99717 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 13 Sep 2019 22:13:42 +0200 Subject: qapi: Permit alternates with just one branch A union or alternate without branches makes no sense and doesn't work: it can't be instantiated. A union or alternate with just one branch works, but is degenerate. We accept the former, but reject the latter. Weird. docs/devel/qapi-code-gen.txt doesn't mention the difference. It claims an alternate definition is "is similar to a simple union type". Permit degenerate alternates to make them consistent with unions. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-10-armbru@redhat.com> --- scripts/qapi/common.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'scripts/qapi') diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c5c7128..99db18f 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -920,11 +920,9 @@ def check_alternate(expr, info): members = expr['data'] types_seen = {} - # Check every branch; require at least two branches - if len(members) < 2: + if len(members) == 0: raise QAPISemError(info, - "Alternate '%s' should have at least two branches " - "in 'data'" % name) + "Alternate '%s' cannot have empty 'data'" % name) for (key, value) in members.items(): check_name(info, "Member of alternate '%s'" % name, key) check_known_keys(info, -- cgit v1.1