-
Notifications
You must be signed in to change notification settings - Fork 803
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 attribute targets on functions #16692
Enforce attribute targets on functions #16692
Conversation
❗ Release notes required
|
…rgets on functions
…rfgp/fsharp into fix-attribute-targets-for-functions
…rfgp/fsharp into fix-attribute-targets-for-functions
This is ready |
Could you please add a small description of the new rules? Like
Will help discoverability of the change + when F# 9 release notes will be prepared. |
Yeah I was working on this. Updated the PR description. Please check the tests and sharplab links and let me know if we can add more test cases |
…rfgp/fsharp into fix-attribute-targets-for-functions
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.
Nice, useful and clear work, thanks for the good PR description, testing and splitting changes into multiple PRs.
As for the TailCall, yeah I think we should at least put the check behind the flag. Maybe we can have even a separate message specifically for the TailCall case although that does sound a bit ad-hoc.
@vzarytovskii @psfinaki with this PR and checking for the language version flag. We will get
Currently we have 2 error number and messages for enforcing the right AttributeTarget in let bindings
My proposal would be to in F#9 use in both cases The most used scenario for this ie when you use a testing library like Xunit and you use the wrong target your tests silently be ignored module MyTests
open Xunit
[<Fact>]
let ``This test will be ignored`` =
Assert.True(false)
[<Fact>
let ``This test will not be ignored`` () =
Assert.True(false) Even the compiler had couple tests suffering from this See #16610 Edit: Xunit related issue xunit/xunit#2064 |
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.
Yeah, that works, thank!
Oh actually if we get rid of that thing with tests, it would be awesome, I've stumbled on that myself multiple times :) |
@auduchinok FYI more AttributeTargets changes |
Description
Fixes #8547
Currently the compiler does not enforce
AttributeTargets
invalues
andfunction bindings
Before
After
Important
AttributeTargets
are not covered by the lang spec The new rules are based on me reading document and using sharplab to see what is the produced code in C#Old Rules
AttributeTargets.Field ||| AttributeTargets.Method ||| AttributeTargets.Property ||| AttributeTargets.ReturnValue
New Rules
AttributeTargets.Field ||| AttributeTargets.Property ||| AttributeTargets.ReturnValue
AttributeTargets.Method ||| AttributeTargets.ReturnValue
Links
Note: this PR only covers
module
andclass
let bindings for now. Will create follow up PR formembers, properties
etcChecklist
Test cases added
Performance benchmarks added in case of performance changes
Release notes entry updated: