dotnet / dotnet/csharpstandard
Missing Attribute Target of `return`
- Dominant language
- C#
- Stars
- 815
- Forks
- 99
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 16
Description
It was first reported in dotnet/roslyn#62145
See the grammar [here](https://github.com/dotnet/csharplang/blob/ms-spec-text/spec/attributes.md#attribute-specification) for the *attribute_target* grammar. Later in that section, the MS spec says:
> - An attribute specified on a set accessor for a property or indexer declaration can apply either to the associated method or to its lone implicit parameter. In the absence of an attribute_target_specifier, the attribute applies to the method. The presence of the method attribute_target_specifier indicates that the attribute applies to the method; the presence of the param attribute_target_specifier indicates that the attribute applies to the parameter; the presence of the return attribute_target_specifier indicates that the attribute applies to the return value.
> - An attribute specified on an add or remove accessor declaration for an event declaration can apply either to the associated method or to its lone parameter. In the absence of an attribute_target_specifier, the attribute applies to the method. The presence of the method attribute_target_specifier indicates that the attribute applies to the method; the presence of the param attribute_target_specifier indicates that the attribute applies to the parameter; the presence of the return attribute_target_specifier indicates that the attribute applies to the return value.
We chose different language in the C# 6 standard.
The standard doesn't specify the behavior for the `return` attribute specifier on `set` accessors, or `event` declaration. The standard says:
> In all other contexts, inclusion of an attribute_target_specifier is permitted but unnecessary.
Later, the standard says:
> An implementation can accept other *attribute_targets*, the purposes of which are implementation defined. An implementation that does not recognize such an *attribute_target* shall issue a warning and ignore the containing attribute_section.
Note that [§B.3](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/portability-issues.md#b3-implementation-defined-behavior) does not list this as one of the areas of implementation-defined behavior.
Question for us on the committee: Should we standardize the roslyn behavior? Should we update §B.3?
Contributor guide
Assessment
This issue has not been assessed yet.