Union members cannot be optional:
{% include “docs/reference/fidl/language/error-catalog/label/_bad.md” %}
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0049.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
Remove the optional
constraint:
{% include “docs/reference/fidl/language/error-catalog/label/_good.md” %}
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0049.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
FIDL does not allow union members to be optional because this can result in many ways of expressing the same value. For example, a union with three optional members would have 6 states (2 per member). Instead, this should be modeled with a fourth member whose type is struct {}
, or by making the overall union optional with Foo:optional
.