未验证 提交 b66628c4 编写于 作者: V Vlad Zarytovskii 提交者: GitHub

F# 7 fixes (#14294)

上级 2adeb15a
......@@ -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]
......
......@@ -19,6 +19,38 @@ let setupCompilation compilation =
|> withReferences [typesModule]
[<Fact>]
let ``Srtp call Zero property returns valid result`` () =
Fsx """
let inline zero<'T when 'T: (static member Zero: 'T)> = 'T.Zero
let result = zero<int>
if result <> 0 then failwith $"Something's wrong: {result}"
"""
|> runFsi
|> shouldSucceed
[<Fact>]
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
[<EntryPoint>]
let main _ =
let result = bar<Foo>
if result <> 0 then
failwith $"Unexpected result: {result}"
0
"""
|> asExe
|> compileAndRun
#if !NETCOREAPP
[<Theory(Skip = "IWSAMs are not supported by NET472.")>]
#else
......@@ -775,7 +807,11 @@ module ``Active patterns`` =
module ``Suppression of System Numerics interfaces on unitized types`` =
[<Fact(Skip = "Solution needs to be updated to .NET 7")>]
#if !NETCOREAPP
[<Fact(Skip = "IWSAMs are not supported by NET472.")>]
#else
[<Fact>]
#endif
let Baseline () =
Fsx """
open System.Numerics
......@@ -785,16 +821,19 @@ module ``Suppression of System Numerics interfaces on unitized types`` =
|> compile
|> shouldSucceed
[<Theory(Skip = "Solution needs to be updated to .NET 7")>]
#if !NETCOREAPP
[<Theory(Skip = "IWSAMs are not supported by NET472.")>]
#else
[<Theory>]
[<InlineData("IAdditionOperators", 3)>]
[<InlineData("IAdditiveIdentity", 2)>]
[<InlineData("IBinaryFloatingPointIeee754", 1)>]
[<InlineData("IBinaryNumber", 1)>]
[<InlineData("IBitwiseOperators", 3)>]
[<InlineData("IComparisonOperators", 2)>]
[<InlineData("IComparisonOperators", 3)>]
[<InlineData("IDecrementOperators", 1)>]
[<InlineData("IDivisionOperators", 3)>]
[<InlineData("IEqualityOperators", 2)>]
[<InlineData("IEqualityOperators", 3)>]
[<InlineData("IExponentialFunctions", 1)>]
[<InlineData("IFloatingPoint", 1)>]
[<InlineData("IFloatingPointIeee754", 1)>]
......@@ -814,6 +853,7 @@ module ``Suppression of System Numerics interfaces on unitized types`` =
[<InlineData("ITrigonometricFunctions", 1)>]
[<InlineData("IUnaryNegationOperators", 2)>]
[<InlineData("IUnaryPlusOperators", 2)>]
#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}>"
......
......@@ -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
[<Fact(Skip = "NET472 is unsupported runtime for this kind of test.")>]
#else
[<Fact>]
......@@ -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
[<Fact(Skip = "IWSAMs are not supported by NET472.")>]
#else
[<Fact>]
#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)
[<EntryPoint>]
let main _ =
let raio = RAIO()
setGetInit raio 111
0
"""
FSharp fsharpSource
|> asExe
|> withLangVersion70
|> withReferences [csharpLib]
|> compile
|> shouldSucceed
#if !NETCOREAPP
[<Fact(Skip = "IWSAMs are not supported by NET472.")>]
#else
[<Fact>]
#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 ``<Clone>$``: unit -> 'T)> (a: 'T) = a.``<Clone>$``()
[<EntryPoint>]
let main _ =
let recd = Recd()
let _ = clone recd
0
"""
FSharp fsharpSource
|> asExe
|> withLangVersion70
|> withReferences [csharpLib]
|> compile
|> shouldSucceed
#if !NETCOREAPP
[<Fact(Skip = "NET472 is unsupported runtime for this kind of test.")>]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册