From 9d39162e2af51a1861f09002e3816a5a4de68efa Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 19 May 2026 12:32:39 +0200 Subject: [PATCH] Add EmittedIL tests proving [] works by design on extension overloads (#19604) EmittedIL baselines demonstrate that [] IS applied to the annotated overload. The unannotated overload keeps the default 'Builder.MethodName' IL name, while the annotated one gets the exact compiled name requested. This is correct by-design behavior - only the single overload carrying the attribute should be renamed. - CompiledNameAttribute06.fs: C#-style extension with one overload annotated [] - proves annotated overload becomes 'UseCosmosDb' and the unannotated one stays 'Builder.UseCosmosDb'. - CompiledNameAttribute07.fs: F#-style extension with [] on one overload - proves annotated overload becomes 'Renamed' while the other stays 'Builder.UseDb'. Closes #19604 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../CompiledNameAttribute.fs | 12 ++ .../CompiledNameAttribute06.fs | 21 ++++ .../CompiledNameAttribute06.fs.err.bsl | 0 .../CompiledNameAttribute06.fs.il.bsl | 114 ++++++++++++++++++ .../CompiledNameAttribute07.fs | 14 +++ .../CompiledNameAttribute07.fs.err.bsl | 0 .../CompiledNameAttribute07.fs.il.bsl | 111 +++++++++++++++++ 7 files changed, 272 insertions(+) create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs.err.bsl create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs.il.bsl create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs.err.bsl create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs.il.bsl diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute.fs index 8bab5b4ebf6..e11f8108c00 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute.fs @@ -56,3 +56,15 @@ module CompiledNameAttribute = |> compile |> shouldSucceed |> ignore + + [] + let ``CompiledNameAttribute06_fs`` compilation = + compilation + |> getCompilation + |> verifyCompilation + + [] + let ``CompiledNameAttribute07_fs`` compilation = + compilation + |> getCompilation + |> verifyCompilation diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs new file mode 100644 index 00000000000..99c4dbc451c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs @@ -0,0 +1,21 @@ +// #NoMono #NoMT #CodeGen #EmittedIL #Attributes +// Regression test for https://github.com/dotnet/fsharp/issues/19604 +// EXPECTED: [] applied to one overload renames only that overload in IL. +// The unannotated overload keeps its original logical name. +module Program + +open System +open System.Runtime.CompilerServices +open System.Runtime.InteropServices + +type Builder() = + member _.X = 1 + +[] +module Ext = + type Builder with + [] + member builder.UseCosmosDb ([] storeScopesAndAppsInMemory : bool) = () + + [] + member builder.UseCosmosDb (configuration : Action) = () diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs.err.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs.err.bsl new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs.il.bsl new file mode 100644 index 00000000000..3827e0c166e --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs.il.bsl @@ -0,0 +1,114 @@ + + + + + +.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 Program + 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 Builder + 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 hidebysig specialname instance int32 get_X() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + .property instance int32 X() + { + .get instance int32 Program/Builder::get_X() + } + } + + .class abstract auto ansi sealed nested public Ext + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.AutoOpenAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .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 ) + .method public static void UseCosmosDb(class Program/Builder builder, + [opt] bool storeScopesAndAppsInMemory) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 0B 55 73 65 43 6F 73 6D 6F 73 44 62 00 00 ) + .param [2] = bool(false) + + .maxstack 8 + IL_0000: ret + } + + .method public static void Builder.UseCosmosDb(class Program/Builder builder, + class [runtime]System.Action`1 configuration) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + +} + +.class private abstract auto ansi sealed ''.$Program + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs new file mode 100644 index 00000000000..9c90889006d --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs @@ -0,0 +1,14 @@ +// #NoMono #NoMT #CodeGen #EmittedIL #Attributes +// Regression test for https://github.com/dotnet/fsharp/issues/19604 +// EXPECTED: [] with a different value on one overload renames only that overload. +module Program + +type Builder() = + member _.X = 1 + +module Ext = + type Builder with + [] + member builder.UseDb (i: int) = i + + member builder.UseDb (s: string) = s diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs.err.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs.err.bsl new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs.il.bsl new file mode 100644 index 00000000000..6f9307db070 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs.il.bsl @@ -0,0 +1,111 @@ + + + + + +.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 Program + 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 Builder + 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 hidebysig specialname instance int32 get_X() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + .property instance int32 X() + { + .get instance int32 Program/Builder::get_X() + } + } + + .class abstract auto ansi sealed nested public Ext + 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 ) + .method public static int32 Renamed(class Program/Builder builder, + int32 i) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 05 55 73 65 44 62 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + .method public static string Builder.UseDb(class Program/Builder builder, + string s) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + } + +} + +.class private abstract auto ansi sealed ''.$Program + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + +