Skip to content

Commit 73714c9

Browse files
authored
Fix: Type checking behavior on interface extension members (#14488)
1 parent ad65b81 commit 73714c9

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Compiler/Checking/CheckExpressions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,7 @@ and CheckIWSAM (cenv: cenv) (env: TcEnv) checkConstraints iwsam m tcref =
43784378
if iwsam = WarnOnIWSAM.Yes && isInterfaceTy g ty && checkConstraints = CheckCxs then
43794379
let tcref = tcrefOfAppTy g ty
43804380
let meths = AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults cenv.infoReader env.NameEnv None ad IgnoreOverrides m ty
4381-
if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot) then
4381+
if meths |> List.exists (fun meth -> not meth.IsInstance && meth.IsDispatchSlot && not meth.IsExtensionMember) then
43824382
warning(Error(FSComp.SR.tcUsingInterfaceWithStaticAbstractMethodAsType(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
43834383

43844384
and TcLongIdentType kindOpt (cenv: cenv) newOk checkConstraints occ iwsam env tpenv synLongId =

tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,28 @@ module ``Equivalence of properties and getters`` =
320320
IL_000e: ret
321321
}"""]
322322

323+
module ``Type checking behavior`` =
324+
325+
#if !NETCOREAPP
326+
[<Theory(Skip = "IWSAMs are not supported by NET472.")>]
327+
#else
328+
[<InlineData("6.0")>]
329+
[<InlineData("7.0")>]
330+
[<Theory>]
331+
#endif
332+
let ``Extension method on interface without SAM does not produce a warning`` version =
333+
Fsx """
334+
type INormalInterface =
335+
abstract member IntMember: int
336+
337+
module INormalInterfaceExtensions =
338+
type INormalInterface with
339+
static member ExtMethod (a: INormalInterface) =
340+
()
341+
"""
342+
|> withLangVersion version
343+
|> compile
344+
|> shouldSucceed
323345

324346
module Negative =
325347

@@ -375,7 +397,6 @@ module Negative =
375397
|> 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."
376398
|> ignore
377399

378-
379400
module InvocationBehavior =
380401

381402
[<Fact>]

tests/FSharp.Test.Utilities/Compiler.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ module rec Compiler =
393393

394394
let withLangVersionPreview (cUnit: CompilationUnit) : CompilationUnit =
395395
withOptionsHelper [ "--langversion:preview" ] "withLangVersionPreview is only supported on F#" cUnit
396+
397+
let withLangVersion (version: string) (cUnit: CompilationUnit) : CompilationUnit =
398+
withOptionsHelper [ $"--langversion:{version}" ] "withLangVersion is only supported on F#" cUnit
396399

397400
let withAssemblyVersion (version:string) (cUnit: CompilationUnit) : CompilationUnit =
398401
withOptionsHelper [ $"--version:{version}" ] "withAssemblyVersion is only supported on F#" cUnit

0 commit comments

Comments
 (0)