Skip to content

Commit 93a88e5

Browse files
committed
add extension member check to CheckIWSAM function
1 parent ad65b81 commit 93a88e5

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-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: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,33 @@ 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("""
329+
type INormalInterface =
330+
abstract member IntMember: int
331+
332+
module INormalInterfaceExtensions =
333+
type INormalInterface with
334+
static member ExtMethod (a: INormalInterface) =
335+
()""")>]
336+
[<Theory>]
337+
#endif
338+
let ``Extension method on interface without SAM does not produce a warning`` code =
339+
Fsx code
340+
|> withLangVersion60
341+
|> compile
342+
|> shouldSucceed
343+
|> ignore
344+
345+
Fsx code
346+
|> withLangVersion70
347+
|> compile
348+
|> shouldSucceed
349+
|> ignore
323350

324351
module Negative =
325352

@@ -375,7 +402,6 @@ module Negative =
375402
|> 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."
376403
|> ignore
377404

378-
379405
module InvocationBehavior =
380406

381407
[<Fact>]

0 commit comments

Comments
 (0)