Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

AttributeUsage.AllowMultiple is not inherited for attributes defined (subclassed) in C# #17107

Open
cmeeren opened this issue Apr 30, 2024 · 0 comments
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@cmeeren
Copy link
Contributor

cmeeren commented Apr 30, 2024

Seems related to #9256.

C# attribute definitions:

[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class BaseAttribute : Attribute;

public class ChildAttribute : BaseAttribute;

This works fine in C#, i.e., the following compiles:

[Child]
[Child]
public class Foo;

However, the following F# code does not:

[<Child>]
[<Child>]
type Foo() = class end

This fails on the second [<Child>] line with FS0429:

Error FS0429 : The attribute type 'ChildAttribute' has 'AllowMultiple=false'. Multiple instances of this attribute cannot be attached to a single language element.

If ChildAttribute is defined in F# instead, it works.

A simple, but of course suboptimal workaround is to subclass the desired (already subclassed) attribute and set the correct AttributeUsage on it.

@github-actions github-actions bot added this to the Backlog milestone Apr 30, 2024
@abonie abonie added Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. Area-Compiler-Checking Type checking, attributes and all aspects of logic checking and removed Needs-Triage labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Status: New
Development

No branches or pull requests

2 participants