diff --git a/src/fsharp/TcGlobals.fs b/src/fsharp/TcGlobals.fs index b574214ecec..0c335fdfff2 100755 --- a/src/fsharp/TcGlobals.fs +++ b/src/fsharp/TcGlobals.fs @@ -1601,6 +1601,11 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d Some (g.array_set_info, [ety], argExprs) | "get_Item", [sty; _; _], _, [_; _] when isStringTy g sty -> Some (g.getstring_info, [], argExprs) + | "op_UnaryPlus", [aty], _, [_] -> + // Call Operators.id + let info = makeOtherIntrinsicValRef (fslib_MFOperators_nleref, "id", None, None, [vara], ([[varaTy]], varaTy)) + let tyargs = [aty] + Some (info, tyargs, argExprs) | _ -> None diff --git a/tests/fsharp/Compiler/Language/CodeQuotationTests.fs b/tests/fsharp/Compiler/Language/CodeQuotationTests.fs new file mode 100644 index 00000000000..c3feb8277a4 --- /dev/null +++ b/tests/fsharp/Compiler/Language/CodeQuotationTests.fs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Test.Utilities.Compiler +open FSharp.Quotations.Patterns + +[] +module CodeQuotationsTests = + + [] + let ``Quotation on op_UnaryPlus(~+) compiles and runs`` () = + Fsx """ +open FSharp.Linq.RuntimeHelpers +open FSharp.Quotations.Patterns +open FSharp.Quotations.DerivedPatterns + +let eval q = LeafExpressionConverter.EvaluateQuotation q + +let inline f x = <@ (~+) x @> +let x = <@ f 1 @> +let y : unit = + match f 1 with + | Call(_, methInfo, _) when methInfo.Name = "op_UnaryPlus" -> + () + | e -> + failwithf "did not expect expression for 'y': %A" e +let z : unit = + match f 5 with + | (CallWithWitnesses(_, methInfo, methInfoW, _, _) as e) when methInfo.Name = "op_UnaryPlus" && methInfoW.Name = "op_UnaryPlus$W" -> + if ((eval e) :?> int) = 5 then + () + else + failwith "did not expect evaluation false" + | e -> + failwithf "did not expect expression for 'z': %A" e + """ + |> asExe + |> withOptions ["--langversion:preview"] + |> compileAndRun + + diff --git a/tests/fsharp/Compiler/Language/WitnessTests.fs b/tests/fsharp/Compiler/Language/WitnessTests.fs new file mode 100644 index 00000000000..67f383c7827 --- /dev/null +++ b/tests/fsharp/Compiler/Language/WitnessTests.fs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Test.Utilities.Compiler +open FSharp.Tests + +#if !NETCOREAPP + +[] +module WitnessTests = + + [] + let ``Witness expressions are created as a result of compiling the type provider tests`` () = + let dir = Core.getTestsDirectory "typeProviders/helloWorld" + Fsx (sprintf """ +#load @"%s" + """ (dir ++ "provider.fsx")) + |> asExe + |> ignoreWarnings + |> withOptions ["--langversion:preview"] + |> compile + |> shouldSucceed + |> ignore +#endif + + diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index db41395b37c..1c4f337025d 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -41,6 +41,8 @@ + +