- 
        Couldn't load subscription status. 
- Fork 833
Enforce AttributeTargets.Class and AttributeTargets.Struct #16790
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
Conversation
| ❗ Release notes required
 
 | 
| This is ready | 
| This will likely break the following scenario: [<Struct; RequireQualifiedAccess>]
type x = { y: int }
let xx = { x.y = 123 } // Works and will emit "The record label 'y' is not defined" diagnostic without "x."Will it now throw  | 
| 
 This is unaffected as this PR checks for  | 
| 
 Ah, good. | 
| What about something like <RequireQualifiedAccess; Struct; NoComparison>]
type ValueOrCancelled<'TResult> =
    | Value of result: 'TResult
    | Cancelled of ``exception``: OperationCanceledExceptionThere might be a bunch of similar cases, with rqa in particular. At the very least we should extend the attribute to structs (possibly other targets). | 
| 
 This is also unaffected as this is PR does NOT check  
 type MyClass() = class end
[<Class>]
type MyClass = ...
type MyStruct(x: int) = struct end
[<Struct>]
type MyStruct(x: int) = ...So records, union and it generic counterparts still works as before. Currently      [<AttributeUsage(AttributeTargets.Class, AllowMultiple=false)>]
    [<Sealed>]
    type RequireQualifiedAccessAttribute() =
        inherit Attribute() | 
| @auduchinok Could you have a look this one please ? | 
| This feels more like a bug fix than a language feature, does it really need to be tied to a language version flag? | 
| 
 Agreed it is a bug, But based on previous PR's on AttributeTargets this code will stop compiling in the next version so we do not want to break existing code, that being said happy to remove the language version flag if the team is happy with | 
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.
Well done and well tested. Thanks!
@T-Gro?
| On top of RQA and AutoOpen, attributes where I think this change can potentially introduce breaks in user code: 
 (I am omitting all attributes working on DUs/records, as this is not the scope of this PR - but might be in the scope of future ones) | 
| 
 @T-Gro Yeah I think the mentioned attributes should updated to target  | 
| 
 | 
| 
 @vzarytovskii Can you create an issue with all the Attributes that needs updating. Happy to do the actual work | 
| 
 I will update them as part of this PR, so potentially breaking change won't accidentally leak into merge/release. | 
| 
 Done | 
| 
 This is done | 
| Thanks @vzarytovskii You rock 🎸 | 
| @T-Gro can you re-review pls? | 
Head branch was pushed to by a user without write access
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.
Looks good now, thanks for incorporating the changes needed.
| /azp run | 
| Azure Pipelines successfully started running 2 pipeline(s). | 
| I guess this PR is taking all merge conflicts today haha | 
| Can we have this now in ? | 
Description
Fixes #13526
Old rule
Classes and Structwere usingAttributeTargets.Class ||| AttributeTargets.Interface ||| AttributeTargets.Delegate ||| AttributeTargets.Struct ||| AttributeTargets.EnumNew rule
AttributeTargets.ClassAttributeTargets.StructBefore
After
Checklist
Test cases added
Performance benchmarks added in case of performance changes
Release notes entry updated: