From 93a88e5550377cbb171cabe4be1d91f1dbb0e9bd Mon Sep 17 00:00:00 2001 From: rosskuehl Date: Sun, 18 Dec 2022 14:23:55 -0500 Subject: [PATCH 1/2] add extension member check to CheckIWSAM function --- src/Compiler/Checking/CheckExpressions.fs | 2 +- .../IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index d4ff82dd1da..54ec31a4451 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4378,7 +4378,7 @@ and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref = if iwsam = WarnOnIWSAM.Yes && isInterfaceTy g ty && checkConstraints = CheckCxs then let tcref = tcrefOfAppTy g ty let meths = AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults cenv.infoReader env.NameEnv None ad IgnoreOverrides m ty - if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot) then + if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tpenv synLongId = diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index a328c5f3df2..a55fd928c8e 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -320,6 +320,33 @@ module ``Equivalence of properties and getters`` = IL_000e: ret }"""] +module ``Type checking behavior`` = + + #if !NETCOREAPP + [] + #else + [] + [] + #endif + let ``Extension method on interface without SAM does not produce a warning`` code = + Fsx code + |> withLangVersion60 + |> compile + |> shouldSucceed + |> ignore + + Fsx code + |> withLangVersion70 + |> compile + |> shouldSucceed + |> ignore module Negative = @@ -375,7 +402,6 @@ module Negative = |> withDiagnosticMessage "The trait 'A' invoked by this call has multiple support types. This invocation syntax is not permitted for such traits. See https://aka.ms/fsharp-srtp for guidance." |> ignore - module InvocationBehavior = [] From 17066f05131a39d994650946a19c5bd8291179ce Mon Sep 17 00:00:00 2001 From: rosskuehl Date: Mon, 19 Dec 2022 09:06:14 -0500 Subject: [PATCH 2/2] make language version an inline data and keep source code in test body --- .../IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs | 23 ++++++++----------- tests/FSharp.Test.Utilities/Compiler.fs | 3 +++ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index a55fd928c8e..44f84521e36 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -325,28 +325,23 @@ module ``Type checking behavior`` = #if !NETCOREAPP [] #else - [] + [] + [] + #endif + let ``Extension method on interface without SAM does not produce a warning`` version = + Fsx """ type INormalInterface = abstract member IntMember: int module INormalInterfaceExtensions = type INormalInterface with static member ExtMethod (a: INormalInterface) = - ()""")>] - [] - #endif - let ``Extension method on interface without SAM does not produce a warning`` code = - Fsx code - |> withLangVersion60 - |> compile - |> shouldSucceed - |> ignore - - Fsx code - |> withLangVersion70 + () + """ + |> withLangVersion version |> compile |> shouldSucceed - |> ignore module Negative = diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 97808b58591..a9090fcf09c 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -393,6 +393,9 @@ module rec Compiler = let withLangVersionPreview (cUnit: CompilationUnit) : CompilationUnit = withOptionsHelper [ "--langversion:preview" ] "withLangVersionPreview is only supported on F#" cUnit + + let withLangVersion (version: string) (cUnit: CompilationUnit) : CompilationUnit = + withOptionsHelper [ $"--langversion:{version}" ] "withLangVersion is only supported on F#" cUnit let withAssemblyVersion (version:string) (cUnit: CompilationUnit) : CompilationUnit = withOptionsHelper [ $"--version:{version}" ] "withAssemblyVersion is only supported on F#" cUnit