Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Type checking behavior on interface extension members #14488

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,28 @@ module ``Equivalence of properties and getters`` =
IL_000e: ret
}"""]

module ``Type checking behavior`` =

#if !NETCOREAPP
[<Theory(Skip = "IWSAMs are not supported by NET472.")>]
vzarytovskii marked this conversation as resolved.
Show resolved Hide resolved
#else
[<InlineData("6.0")>]
[<InlineData("7.0")>]
[<Theory>]
#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) =
()
"""
|> withLangVersion version
|> compile
|> shouldSucceed

module Negative =

Expand Down Expand Up @@ -375,7 +397,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 =

[<Fact>]
Expand Down
3 changes: 3 additions & 0 deletions tests/FSharp.Test.Utilities/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down