-
Notifications
You must be signed in to change notification settings - Fork 832
Enforce union case declarations AttributeTargets #16764
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
Enforce union case declarations AttributeTargets #16764
Conversation
❗ Release notes required
|
….com:edgarfgp/fsharp into enforce-attribute-targets-on-union-case-decl
|
This is ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix, tests and refactoring. That's a good one.
I wonder if we should add some notes to some docs about it. This is a technically correct behavior but might seem unintuitive to F# newcomers.
Im planning to submit a RFC with the |
|
Awesome :) |
|
This PR should merged before #16790. Thanks |
|
@dotnet/fsharp-team-msft |
Co-authored-by: Brian Rourke Boll <brianrourkeboll@users.noreply.github.com>
Thought it's a breaking change, I think it's fine from the the "correctness" point of view, however having If something is using generated attributes, they can be "correctly" utilised in C#, but not in F#, since from F# standpoint, That said, I don't mind merging it as it is now, but it still feels weird to me that we allow |
@vzarytovskii As you know there not an actual spec yet for this, so if |
This is not always the case. There's no single direct mapping between union cases and their compiled .NET representations: depending on the union and its union cases, they compile to different things (nested classes, properties, constructor methods, case test properties, nested For example, these union cases compile to properties, not methods: type U =
| A
| BI don't see any tests covering these cases. Is there an RFC for this? |
@auduchinok No Yet. Im going through the issues and figuring out which
I will look into this as create a PR with tests |
| let attrs = | ||
| // The attributes of a union case decl get attached to the generated "static factory" method | ||
| // Enforce that the union-cases can only be targeted by attributes with AttributeTargets.Method | ||
| if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargetsUnionCaseDeclarations) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the logic from IlxGen, this should branch on arguments for the case.
Case with no data is a property.
Case with fields is a method.
There are other concerns affecting DU IL generation (structness, null as true value, number of cases), but so far I have not found any other affecting case-level attribute placement beyond what I wrote above (and what Eugene pointed out).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. See #16807
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you find any other case. Let me know, I really want to improve this area of the compiler
Description
Fixes #3112
UnionCase compiles down to a static
Methodso should only enforceAttributeTargets.MethodSharpLabOld Rule
New Rule
Checklist
Test cases added
Performance benchmarks added in case of performance changes
Release notes entry updated: