On 02/20/2014 07:43 AM, Markus Armbruster wrote:
> Wenchao Xia <xiaw...@linux.vnet.ibm.com> writes:
> 
>> It will check whether base is set, whether discriminator is found
>> in base, whether the values specified are written correctly, and
>> whether all enum values are covered, when discriminator is a

> 
> And every member of the discriminator enum type must also occur as key
> of the union's member 'data'.  Why?
> 
> Consider:
> 
>     { 'enum': 'FooEnum', 'data': [ 'plain', 'bells', 'whistles' ] }
> 
>     { 'type': 'CommonFooOptions',
>       'data': { 'type: 'FooType', 'readonly': 'bool' } }
>     { 'union': 'FooOptions',
>       'base': 'CommonFooOptions',
>       'discriminator': 'type',
>       'data': { 'bells': 'BellsOptions',
>                 'whistles': 'WhistlesOptions' } }
> 
> Type 'plain' doesn't have options beyond CommonFooOptions.

I'd still rather make it explicit that we KNOW that this branch of the
union has no additional options:

{ 'union': 'FooOptions',
  'base': 'CommonFooOptions',
  'discriminator': 'type',
  'data': { 'plain': {},
            'bells': 'BellsOptions',
            'whistles': 'WhistlesOptions' } }

to show that we explicitly thought about all the cases.  We don't
currently have any such unions with an empty branch, but it would be
worth documenting in the qapi text and explicitly testing that it works
if we intend to support this.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to