Skip to content

Commit b8b40f5

Browse files
authored
Warn on inconsistent [<CompiledName>] across extension overloads (#19737)
* Detect inconsistent [<CompiledName>] across extension overloads (#19604)
1 parent d0e593f commit b8b40f5

7 files changed

Lines changed: 272 additions & 0 deletions

File tree

tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,15 @@ module CompiledNameAttribute =
5656
|> compile
5757
|> shouldSucceed
5858
|> ignore
59+
60+
[<Theory; FileInlineData("CompiledNameAttribute06.fs")>]
61+
let ``CompiledNameAttribute06_fs`` compilation =
62+
compilation
63+
|> getCompilation
64+
|> verifyCompilation
65+
66+
[<Theory; FileInlineData("CompiledNameAttribute07.fs")>]
67+
let ``CompiledNameAttribute07_fs`` compilation =
68+
compilation
69+
|> getCompilation
70+
|> verifyCompilation
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// #NoMono #NoMT #CodeGen #EmittedIL #Attributes
2+
// Regression test for https://github.com/dotnet/fsharp/issues/19604
3+
// EXPECTED: [<CompiledName>] applied to one overload renames only that overload in IL.
4+
// The unannotated overload keeps its original logical name.
5+
module Program
6+
7+
open System
8+
open System.Runtime.CompilerServices
9+
open System.Runtime.InteropServices
10+
11+
type Builder() =
12+
member _.X = 1
13+
14+
[<AutoOpen; Extension>]
15+
module Ext =
16+
type Builder with
17+
[<Extension; CompiledName "UseCosmosDb">]
18+
member builder.UseCosmosDb ([<Optional; DefaultParameterValue false>] storeScopesAndAppsInMemory : bool) = ()
19+
20+
[<Extension>]
21+
member builder.UseCosmosDb (configuration : Action<int>) = ()

tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute06.fs.err.bsl

Whitespace-only changes.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
2+
3+
4+
5+
6+
.assembly extern runtime { }
7+
.assembly extern FSharp.Core { }
8+
.assembly assembly
9+
{
10+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32,
11+
int32,
12+
int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 )
13+
14+
15+
16+
17+
.hash algorithm 0x00008004
18+
.ver 0:0:0:0
19+
}
20+
.module assembly.exe
21+
22+
.imagebase {value}
23+
.file alignment 0x00000200
24+
.stackreserve 0x00100000
25+
.subsystem 0x0003
26+
.corflags 0x00000001
27+
28+
29+
30+
31+
32+
.class public abstract auto ansi sealed Program
33+
extends [runtime]System.Object
34+
{
35+
.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 )
36+
.class auto ansi serializable nested public Builder
37+
extends [runtime]System.Object
38+
{
39+
.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 )
40+
.method public specialname rtspecialname instance void .ctor() cil managed
41+
{
42+
43+
.maxstack 8
44+
IL_0000: ldarg.0
45+
IL_0001: callvirt instance void [runtime]System.Object::.ctor()
46+
IL_0006: ldarg.0
47+
IL_0007: pop
48+
IL_0008: ret
49+
}
50+
51+
.method public hidebysig specialname instance int32 get_X() cil managed
52+
{
53+
54+
.maxstack 8
55+
IL_0000: ldc.i4.1
56+
IL_0001: ret
57+
}
58+
59+
.property instance int32 X()
60+
{
61+
.get instance int32 Program/Builder::get_X()
62+
}
63+
}
64+
65+
.class abstract auto ansi sealed nested public Ext
66+
extends [runtime]System.Object
67+
{
68+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.AutoOpenAttribute::.ctor() = ( 01 00 00 00 )
69+
.custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 )
70+
.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 )
71+
.method public static void UseCosmosDb(class Program/Builder builder,
72+
[opt] bool storeScopesAndAppsInMemory) cil managed
73+
{
74+
.custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 )
75+
.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 )
76+
.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 )
77+
.param [2] = bool(false)
78+
79+
.maxstack 8
80+
IL_0000: ret
81+
}
82+
83+
.method public static void Builder.UseCosmosDb(class Program/Builder builder,
84+
class [runtime]System.Action`1<int32> configuration) cil managed
85+
{
86+
.custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 )
87+
.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 )
88+
89+
.maxstack 8
90+
IL_0000: ret
91+
}
92+
93+
}
94+
95+
}
96+
97+
.class private abstract auto ansi sealed '<StartupCode$assembly>'.$Program
98+
extends [runtime]System.Object
99+
{
100+
.method public static void main@() cil managed
101+
{
102+
.entrypoint
103+
104+
.maxstack 8
105+
IL_0000: ret
106+
}
107+
108+
}
109+
110+
111+
112+
113+
114+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// #NoMono #NoMT #CodeGen #EmittedIL #Attributes
2+
// Regression test for https://github.com/dotnet/fsharp/issues/19604
3+
// EXPECTED: [<CompiledName>] with a different value on one overload renames only that overload.
4+
module Program
5+
6+
type Builder() =
7+
member _.X = 1
8+
9+
module Ext =
10+
type Builder with
11+
[<CompiledName "Renamed">]
12+
member builder.UseDb (i: int) = i
13+
14+
member builder.UseDb (s: string) = s

tests/FSharp.Compiler.ComponentTests/EmittedIL/CompiledNameAttribute/CompiledNameAttribute07.fs.err.bsl

Whitespace-only changes.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
3+
4+
5+
6+
.assembly extern runtime { }
7+
.assembly extern FSharp.Core { }
8+
.assembly assembly
9+
{
10+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32,
11+
int32,
12+
int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 )
13+
14+
15+
16+
17+
.hash algorithm 0x00008004
18+
.ver 0:0:0:0
19+
}
20+
.module assembly.exe
21+
22+
.imagebase {value}
23+
.file alignment 0x00000200
24+
.stackreserve 0x00100000
25+
.subsystem 0x0003
26+
.corflags 0x00000001
27+
28+
29+
30+
31+
32+
.class public abstract auto ansi sealed Program
33+
extends [runtime]System.Object
34+
{
35+
.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 )
36+
.class auto ansi serializable nested public Builder
37+
extends [runtime]System.Object
38+
{
39+
.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 )
40+
.method public specialname rtspecialname instance void .ctor() cil managed
41+
{
42+
43+
.maxstack 8
44+
IL_0000: ldarg.0
45+
IL_0001: callvirt instance void [runtime]System.Object::.ctor()
46+
IL_0006: ldarg.0
47+
IL_0007: pop
48+
IL_0008: ret
49+
}
50+
51+
.method public hidebysig specialname instance int32 get_X() cil managed
52+
{
53+
54+
.maxstack 8
55+
IL_0000: ldc.i4.1
56+
IL_0001: ret
57+
}
58+
59+
.property instance int32 X()
60+
{
61+
.get instance int32 Program/Builder::get_X()
62+
}
63+
}
64+
65+
.class abstract auto ansi sealed nested public Ext
66+
extends [runtime]System.Object
67+
{
68+
.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 )
69+
.method public static int32 Renamed(class Program/Builder builder,
70+
int32 i) cil managed
71+
{
72+
.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 )
73+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 05 55 73 65 44 62 00 00 )
74+
75+
.maxstack 8
76+
IL_0000: ldarg.1
77+
IL_0001: ret
78+
}
79+
80+
.method public static string Builder.UseDb(class Program/Builder builder,
81+
string s) cil managed
82+
{
83+
.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 )
84+
85+
.maxstack 8
86+
IL_0000: ldarg.1
87+
IL_0001: ret
88+
}
89+
90+
}
91+
92+
}
93+
94+
.class private abstract auto ansi sealed '<StartupCode$assembly>'.$Program
95+
extends [runtime]System.Object
96+
{
97+
.method public static void main@() cil managed
98+
{
99+
.entrypoint
100+
101+
.maxstack 8
102+
IL_0000: ret
103+
}
104+
105+
}
106+
107+
108+
109+
110+
111+

0 commit comments

Comments
 (0)