-
Couldn't load subscription status.
- Fork 833
Respect the return qualifier for attributes on class methods #19025
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9360,6 +9360,14 @@ and GenMethodForBinding | |
| g.DebuggerNonUserCodeAttribute | ||
| ] | ||
|
|
||
| // Remove attributes that are applied to the return. These attributes need to be passed through ValRef.Attribs so that | ||
| // ActivePatternElemsOfValRef will correctly propagate `[<return: Struct>]` on active patterns. | ||
| let attrs = | ||
| attrs | ||
| |> List.filter (function | ||
| | Attrib(targetsOpt = Some flags) -> not (flags.HasFlag(AttributeTargets.ReturnValue)) | ||
| | _ -> true) | ||
|
|
||
|
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. Instead of filtering, one could partition and move the return attributes into This would be the smaller change, but I feel it would continue the mis-propagation of attributes... |
||
| let ilAttrsThatGoOnPrimaryItem = | ||
| [ | ||
| yield! GenAttrs cenv eenv attrs | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| open System.Diagnostics.CodeAnalysis | ||
|
|
||
| type Class() = | ||
| [<return: NotNull>] | ||
| static member ClassMethod () = obj() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| .assembly extern runtime { } | ||
| .assembly extern FSharp.Core { } | ||
| .assembly assembly | ||
| { | ||
| .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, | ||
| int32, | ||
| int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| .hash algorithm 0x00008004 | ||
| .ver 0:0:0:0 | ||
| } | ||
| .module assembly.exe | ||
|
|
||
| .imagebase {value} | ||
| .file alignment 0x00000200 | ||
| .stackreserve 0x00100000 | ||
| .subsystem 0x0003 | ||
| .corflags 0x00000001 | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| .class public abstract auto ansi sealed assembly | ||
| extends [runtime]System.Object | ||
| { | ||
| .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) | ||
| .class auto ansi serializable nested public Class | ||
| extends [runtime]System.Object | ||
| { | ||
| .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) | ||
| .method public specialname rtspecialname instance void .ctor() cil managed | ||
| { | ||
|
|
||
| .maxstack 8 | ||
| IL_0000: ldarg.0 | ||
| IL_0001: callvirt instance void [runtime]System.Object::.ctor() | ||
| IL_0006: ldarg.0 | ||
| IL_0007: pop | ||
| IL_0008: ret | ||
| } | ||
|
|
||
| .method public static object ClassMethod() cil managed | ||
| { | ||
| .param [0] | ||
| .custom instance void [runtime]System.Diagnostics.CodeAnalysis.NotNullAttribute::.ctor() = ( 01 00 00 00 ) | ||
|
|
||
| .maxstack 8 | ||
| IL_0000: newobj instance void [runtime]System.Object::.ctor() | ||
| IL_0005: ret | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| .class private abstract auto ansi sealed '<StartupCode$assembly>'.$assembly | ||
| extends [runtime]System.Object | ||
| { | ||
| .method public static void main@() cil managed | ||
| { | ||
| .entrypoint | ||
|
|
||
| .maxstack 8 | ||
| IL_0000: ret | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
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.
Please minimise the diff. So it is easier to review.
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've removed the white-space churn and also fixed a bug this introduced that caused recursive active pattern matches that return struct to fail (see test
Rec struct active pattern is possible).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. To fix the formatting we need to restore the dotnet tools and run
dotnet fantomas .