未验证 提交 73714c94 编写于 作者: R Ross Kuehl 提交者: GitHub

Fix: Type checking behavior on interface extension members (#14488)

上级 ad65b819
......@@ -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 =
......
......@@ -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.")>]
#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 =
......@@ -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>]
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册