| ## fi-0022: Cannot attach attribute to identifier {:#fi-0022} |
| |
| This error occurs when an attribute is placed on the type of a declaration |
| when that type is an identifier type. For example, placing an attribute after |
| field name but before the field's type in a struct declaration associates the |
| attribute with the type of the field rather than with the field itself. If the |
| type of the field is a preexisting type being referenced by name, additional |
| attributes cannot be applied to it. |
| |
| {% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %} |
| |
| ```fidl |
| {% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0022.noformat.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %} |
| ``` |
| |
| If the intent was to apply an attribute to the field, the attribute should be |
| moved before the field name. |
| |
| Attributes can be applied to types where they are declared. This means that if |
| the type of a struct field or other similar declaration is an anonymous type |
| rather than an identifier type, attributes can be applied to the type. |
| |
| {% include "docs/reference/fidl/language/error-catalog/label/_good.md" %} |
| |
| ```fidl |
| {% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0022.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %} |
| ``` |