-
Notifications
You must be signed in to change notification settings - Fork 815
Make attribute target mismatch a warning and not an error. #18492
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
base: main
Are you sure you want to change the base?
Changes from all commits
1799aaf
55507e9
1738018
65f5bb6
0c97b9d
6f2b706
e8f1bb0
75d8f5e
4f2e97e
63be5d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,7 +245,7 @@ namespace N | |
|
||
[<FSharp.Test.FactForNETCOREAPP>] | ||
let ``Warn successfully for invalid tailcalls in type methods`` () = | ||
""" | ||
FSharp """ | ||
namespace N | ||
module M = | ||
|
@@ -261,29 +261,12 @@ namespace N | |
printfn "M2 called" | ||
this.M1() + 2 // should warn | ||
""" | ||
|> FSharp | ||
|> withLangVersion80 | ||
|> compile | ||
|> shouldFail | ||
|> withResults [ | ||
{ Error = Warning 3569 | ||
Range = { StartLine = 10 | ||
StartColumn = 17 | ||
EndLine = 10 | ||
EndColumn = 26 } | ||
Message = | ||
"The member or function 'M2' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." } | ||
{ Error = Warning 3569 | ||
Range = { StartLine = 15 | ||
StartColumn = 17 | ||
EndLine = 15 | ||
EndColumn = 26 } | ||
Message = | ||
#if Debug | ||
"The member or function 'M2' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." } | ||
#else | ||
"The member or function 'M1' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way." } | ||
#endif | ||
|> withDiagnostics [ | ||
(Warning 3569, Line 10, Col 17, Line 10, Col 26, "The member or function 'M2' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way."); | ||
(Warning 3569, Line 15, Col 17, Line 15, Col 26, "The member or function 'M1' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way.") | ||
] | ||
|
||
[<FSharp.Test.FactForNETCOREAPP>] | ||
|
@@ -1481,7 +1464,10 @@ namespace N | |
|> withLangVersionPreview | ||
|> compile | ||
|> shouldFail | ||
|> withSingleDiagnostic (Error 842, Line 6, Col 11, Line 6, Col 19, "This attribute is not valid for use on this language element") | ||
|> withDiagnostics [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there another error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe |
||
(Warning 842, Line 6, Col 11, Line 6, Col 19, "This attribute is not valid for use on this language element") | ||
(Warning 3861, Line 7, Col 13, Line 7, Col 18, "The TailCall attribute should only be applied to recursive functions.") | ||
] | ||
|
||
[<FSharp.Test.FactForNETCOREAPP>] | ||
let ``Error about attribute on recursive let-bound value`` () = | ||
|
@@ -1497,7 +1483,7 @@ namespace N | |
|> withLangVersionPreview | ||
|> compile | ||
|> shouldFail | ||
|> withSingleDiagnostic (Error 842, Line 6, Col 11, Line 6, Col 19, "This attribute is not valid for use on this language element") | ||
|> withSingleDiagnostic (Warning 842, Line 6, Col 11, Line 6, Col 19, "This attribute is not valid for use on this language element") | ||
|
||
[<FSharp.Test.FactForNETCOREAPP>] | ||
let ``Warn about self-defined attribute`` () = // is the analysis available for users of older FSharp.Core versions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ match () with | |
dumpDiagnostics checkResults |> shouldEqual [ | ||
"(3,2--3,25): Attributes are not allowed within patterns" | ||
"(3,4--3,23): This attribute is not valid for use on this language element" | ||
"(3,17--3,22): This is not a valid constant expression or custom attribute value" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we getting a new error here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe |
||
] | ||
|
||
|
||
|
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.
I would still want to address the fact that for union cases and popular serialization libraries using
[DataMember]
, there is not much people can do.For the particular scenario of having attribute on a union case like here : #18298 , and admitting this is a common scenario and does not crash at runtime, we should avoid producing warnings against which users cannot taky any action.
If this scenario would be coverage with a separate warning that would also be opt-in and not opt-out, we would not trigger hard to explain warning by mere updates of the SDK.
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.
More specifically, I think the scenario would be a
Property
-targeting attribute used on a DU case no matter the DU-layout chosen.(if the layout happens to be a property as well, all good. If it isn't, raise a new separate opt-in warning)
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 I was planning to add a new warning(off by default) in a separate PR to address the attribute on a union case with fields.