qapi: Fix broken discriminator error messages

check_union() checks the discriminator exists in base and makes sense.
Two error messages mention the base.  These are broken for anonymous
bases, as demonstrated by tests flat-union-invalid-discriminator and
flat-union-invalid-if-discriminator.err.  The third one doesn't
bother.

First broken when commit ac4338f8eb "qapi: Allow anonymous base for
flat union" (v2.6.0) neglected to adjust the "not a member of base"
error message.  Commit ccadd6bcba "qapi: Add 'if' to implicit struct
members" (v4.0.0) then cloned the flawed error message.

Dumb them down not to mention the base.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190914153506.2151-11-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Markus Armbruster 2019-09-14 17:34:57 +02:00
parent 9d55380b5a
commit 887a2069f7
7 changed files with 8 additions and 11 deletions

View File

@ -877,14 +877,13 @@ def check_union(expr, info):
discriminator_value = base_members.get(discriminator)
if not discriminator_value:
raise QAPISemError(info,
"Discriminator '%s' is not a member of base "
"struct '%s'"
% (discriminator, base))
"Discriminator '%s' is not a member of 'base'"
% discriminator)
if discriminator_value.get('if'):
raise QAPISemError(
info,
"The discriminator %s.%s for union %s must not be conditional"
% (base, discriminator, name))
"The discriminator '%s' for union %s must not be conditional"
% (discriminator, name))
enum_define = enum_types.get(discriminator_value['type'])
# Do not allow string discriminator
if not enum_define:

View File

@ -1 +1 @@
tests/qapi-schema/flat-union-invalid-discriminator.json:11: Discriminator 'enum_wrong' is not a member of base struct 'OrderedDict([('enum1', {'type': 'TestEnum'})])'
tests/qapi-schema/flat-union-invalid-discriminator.json:10: Discriminator 'enum_wrong' is not a member of 'base'

View File

@ -1,4 +1,3 @@
# FIXME error message shows base as OrderedDict
{ 'enum': 'TestEnum',
'data': [ 'value1', 'value2' ] }

View File

@ -1 +1 @@
tests/qapi-schema/flat-union-invalid-if-discriminator.json:11: The discriminator OrderedDict([('enum1', OrderedDict([('type', 'TestEnum'), ('if', 'FOO')]))]).enum1 for union TestUnion must not be conditional
tests/qapi-schema/flat-union-invalid-if-discriminator.json:10: The discriminator 'enum1' for union TestUnion must not be conditional

View File

@ -1,4 +1,3 @@
# FIXME error message shows base as OrderedDict
{ 'enum': 'TestEnum',
'data': [ 'value1', 'value2' ] }

View File

@ -1 +1 @@
tests/qapi-schema/flat-union-optional-discriminator.json:7: Discriminator 'switch' is not a member of base struct 'Base'
tests/qapi-schema/flat-union-optional-discriminator.json:7: Discriminator 'switch' is not a member of 'base'

View File

@ -1 +1 @@
tests/qapi-schema/union-base-empty.json:5: Discriminator 'type' is not a member of base struct 'Empty'
tests/qapi-schema/union-base-empty.json:5: Discriminator 'type' is not a member of 'base'