Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Inconsistent behavior of attribute target specifiers on events #77254

Open
jjonescz opened this issue Feb 17, 2025 · 0 comments
Open

Inconsistent behavior of attribute target specifiers on events #77254

jjonescz opened this issue Feb 17, 2025 · 0 comments
Labels
Area-Compilers Bug untriaged Issues and PRs which have not yet been triaged by a lead
Milestone

Comments

@jjonescz
Copy link
Member

jjonescz commented Feb 17, 2025

Version used: 80ccf3f

using System;

[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class A : Attribute { public A(int i) { } }

class C
{
    [A(1)] [method: A(2)] [param: A(3)] [return: A(4)] [field: A(5)] event Action E;
}
  • Warning is reported that [param:] is an invalid attribute location. However, the attribute is actually emitted to metadata for the param. This seems like a compiler bug. Per the current spec, the warning is correct, the emit is wrong. Ideally, the spec would be changed to allow this. Alternatively, the compiler could be fixed to not emit the attribute - that's a breaking change, though.
  • It feels like [param:] and [return:] should be allowed for field-like and extern events. Those don't have user-defined accessors so there is no other way to specify such attributes. This would need a spec change.
  • The spec doesn't seem to allow [method:] on extern events either (it's allowed only on field-like events), but that's currently allowed by the compiler. Ideally, the spec would be changed to allow this.

See also #77182 (comment).

To get started on implementing this, consider reverting this commit: d38b97c

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Feb 17, 2025
@jjonescz jjonescz added the Bug label Feb 17, 2025
@jaredpar jaredpar added this to the Backlog milestone Feb 25, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Area-Compilers Bug untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants