Indeed, there's no way to express this.

In fact, you also can't write code that constructs such a message: in order
to cause `second` to become the active union field, you either need to call
`initSecond(n)` or `setSecond()`, either of which replaces the default.

So arguably the weird thing here is that you're allowed to assign a default
value to a non-default union member, since said default will never be used.

-Kenton

On Tue, Jun 14, 2016 at 9:19 AM, Ross Light <[email protected]> wrote:

> Not that this has practical use, but I noticed a weird edge case with
> constants, unions, and default values:
>
> @0xf5c9d5529d822584;
>
> struct Foo {
>   union {
>     first @0 :Void;
>     second @1 :Text = "mydefault";
>   }
> }
>
> // Now I want to construct Foo with the discriminant set to second, but
> using the default value:
> const bar = (second = ???);
>
> AFAICT from glancing at the parser code, there is nothing I can put inside
> Foo to represent that specific value.  This is probably okay, but thought
> I'd share the discovery.
>
> -Ross
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at https://groups.google.com/group/capnproto.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to