diff --git a/src/Compiler/TypedTree/TcGlobals.fs b/src/Compiler/TypedTree/TcGlobals.fs index 9eaac69024a4bf67846e18520a253790c36bf2d4..96dc59428e2fbe9c68cf41a3952dde7f9e2480b4 100755 --- a/src/Compiler/TypedTree/TcGlobals.fs +++ b/src/Compiler/TypedTree/TcGlobals.fs @@ -1831,12 +1831,12 @@ type TcGlobals( let info = makeOtherIntrinsicValRef (fslib_MFOperators_nleref, "atan2", None, Some "Atan2", [vara; varb], ([[varaTy]; [varaTy]], varbTy)) let tyargs = [aty;bty] Some (info, tyargs, argExprs) - | "get_Zero", _, Some aty, [_] -> + | "get_Zero", _, Some aty, ([] | [_]) -> // Call LanguagePrimitives.GenericZero let info = makeOtherIntrinsicValRef (fslib_MFLanguagePrimitives_nleref, "GenericZero", None, None, [vara], ([], varaTy)) let tyargs = [aty] Some (info, tyargs, []) - | "get_One", _, Some aty, [_] -> + | "get_One", _, Some aty, ([] | [_]) -> // Call LanguagePrimitives.GenericOne let info = makeOtherIntrinsicValRef (fslib_MFLanguagePrimitives_nleref, "GenericOne", None, None, [vara], ([], varaTy)) let tyargs = [aty] diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs index 9abba91ca2fe69cbe407f30e5987eb925693daab..a328c5f3df28327b8c04d50062c2dd0a481def23 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/TypesAndTypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs @@ -19,6 +19,38 @@ let setupCompilation compilation = |> withReferences [typesModule] +[] +let ``Srtp call Zero property returns valid result`` () = + Fsx """ +let inline zero<'T when 'T: (static member Zero: 'T)> = 'T.Zero +let result = zero +if result <> 0 then failwith $"Something's wrong: {result}" + """ + |> runFsi + |> shouldSucceed + +[] +let ``Srtp call to custom property returns valid result`` () = + FSharp """ +module Foo +type Foo = + static member Bar = 1 + +type HasBar<'T when 'T: (static member Bar: int)> = 'T + +let inline bar<'T when HasBar<'T>> = + 'T.Bar + +[] +let main _ = + let result = bar + if result <> 0 then + failwith $"Unexpected result: {result}" + 0 + """ + |> asExe + |> compileAndRun + #if !NETCOREAPP [] #else @@ -775,7 +807,11 @@ module ``Active patterns`` = module ``Suppression of System Numerics interfaces on unitized types`` = - [] +#if !NETCOREAPP + [] +#else + [] +#endif let Baseline () = Fsx """ open System.Numerics @@ -785,16 +821,19 @@ module ``Suppression of System Numerics interfaces on unitized types`` = |> compile |> shouldSucceed - [] +#if !NETCOREAPP + [] +#else + [] [] [] [] [] [] - [] + [] [] [] - [] + [] [] [] [] @@ -814,6 +853,7 @@ module ``Suppression of System Numerics interfaces on unitized types`` = [] [] [] +#endif let ``Unitized type shouldn't be compatible with System.Numerics.I*`` name paramCount = let typeParams = Seq.replicate paramCount "'T" |> String.concat "," let genericType = $"{name}<{typeParams}>" diff --git a/tests/FSharp.Compiler.ComponentTests/Interop/RequiredAndInitOnlyProperties.fs b/tests/FSharp.Compiler.ComponentTests/Interop/RequiredAndInitOnlyProperties.fs index a3e6b6b6ed7d708f250dbf3a8f6eed89fa7b9b54..0b2d4cc37ab18813e490f4cef4ea86c1d45fb38d 100644 --- a/tests/FSharp.Compiler.ComponentTests/Interop/RequiredAndInitOnlyProperties.fs +++ b/tests/FSharp.Compiler.ComponentTests/Interop/RequiredAndInitOnlyProperties.fs @@ -8,6 +8,14 @@ open System module ``Required and init-only properties`` = + let csharpRecord = + CSharp """ + namespace RequiredAndInitOnlyProperties + { + public record Recd(); + + }""" |> withCSharpLanguageVersion CSharpLanguageVersion.Preview |> withName "csLib" + let csharpBaseClass = CSharp """ namespace RequiredAndInitOnlyProperties @@ -228,7 +236,7 @@ let main _ = Error 810, Line 9, Col 5, Line 9, Col 21, "Cannot call 'set_GetInit' - a setter for init-only property, please use object initialization instead. See https://aka.ms/fsharp-assigning-values-to-properties-at-initialization" ] - #if !NETCOREAPP +#if !NETCOREAPP [] #else [] @@ -259,6 +267,63 @@ let main _ = Error 810, Line 9, Col 38, Line 9, Col 40, "Init-only property 'GetInit' cannot be set outside the initialization code. See https://aka.ms/fsharp-assigning-values-to-properties-at-initialization" ] +#if !NETCOREAPP + [] +#else + [] +#endif + let ``F# can change init-only property via SRTP`` () = + + let csharpLib = csharpBaseClass + + let fsharpSource = + """ +open System +open RequiredAndInitOnlyProperties + +let inline setGetInit<'T when 'T : (member set_GetInit: int -> unit)> (a: 'T) (x: int) = a.set_GetInit(x) + +[] +let main _ = + let raio = RAIO() + setGetInit raio 111 + 0 +""" + FSharp fsharpSource + |> asExe + |> withLangVersion70 + |> withReferences [csharpLib] + |> compile + |> shouldSucceed + + #if !NETCOREAPP + [] +#else + [] +#endif + let ``F# can call special-named methods via SRTP`` () = + + let csharpLib = csharpRecord + + let fsharpSource = + """ +open System +open RequiredAndInitOnlyProperties + +let inline clone<'T when 'T : (member ``$``: unit -> 'T)> (a: 'T) = a.``$``() + +[] +let main _ = + let recd = Recd() + let _ = clone recd + 0 +""" + FSharp fsharpSource + |> asExe + |> withLangVersion70 + |> withReferences [csharpLib] + |> compile + |> shouldSucceed #if !NETCOREAPP []