Skip to content
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
6 changes: 5 additions & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4069,6 +4069,10 @@ module TcDeclarations =
tcref.Deref.IsFSharpDelegateTycon ||
tcref.Deref.IsFSharpEnumTycon

let isDelegateOrEnum =
tcref.Deref.IsFSharpDelegateTycon ||
tcref.Deref.IsFSharpEnumTycon

let reqTypars = tcref.Typars m

// Member definitions are intrinsic (added directly to the type) if:
Expand Down Expand Up @@ -4104,7 +4108,7 @@ module TcDeclarations =
// Note we return 'reqTypars' for intrinsic extensions since we may only have given warnings
IntrinsicExtensionBinding, reqTypars
else
if isInSameModuleOrNamespace && isInterfaceOrDelegateOrEnum then
if isInSameModuleOrNamespace && isDelegateOrEnum then
errorR(Error(FSComp.SR.tcMembersThatExtendInterfaceMustBePlacedInSeparateModule(), tcref.Range))
if nReqTypars <> synTypars.Length then
error(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m))
Expand Down
18 changes: 18 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/Language/InterfaceTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ type I<'T> =
(Error 3350, Line 4, Col 19, Line 4, Col 23, "Feature 'Static members in interfaces' is not available in F# 7.0. Please use language version 8.0 or greater.")
]

[<Fact>]
let ``Concrete static members are allowed in interfaces as intrinsics in lang preview``() =
FSharp $"""
[<Interface>]
type I<'T> =
static member Prop = Unchecked.defaultof<'T>
type I<'T> with
static member Echo (x: 'T) = x

if I<int>.Echo 42 <> 42 || I<int>.Prop <> 0 || not (isNull I<string>.Prop) then
failwith "failed"
"""
|> withLangVersion80
|> asExe
|> compileAndRun
|> shouldSucceed


[<Fact>]
let ``Interface with concrete static members can be implemented in lang preview``() =
FSharp $"""
Expand Down