diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 7cbc0358a29..eb1597f0a31 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -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: @@ -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)) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/InterfaceTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/InterfaceTests.fs index 4bfda202bbf..261a8d9ef4c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/InterfaceTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/InterfaceTests.fs @@ -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.") ] +[] +let ``Concrete static members are allowed in interfaces as intrinsics in lang preview``() = + FSharp $""" +[] +type I<'T> = + static member Prop = Unchecked.defaultof<'T> +type I<'T> with + static member Echo (x: 'T) = x + +if I.Echo 42 <> 42 || I.Prop <> 0 || not (isNull I.Prop) then + failwith "failed" + """ + |> withLangVersion80 + |> asExe + |> compileAndRun + |> shouldSucceed + + [] let ``Interface with concrete static members can be implemented in lang preview``() = FSharp $"""