Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 3 additions & 14 deletions src/fsharp/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2634,6 +2634,8 @@ namespace Microsoft.FSharp.Core
elif type2eq<'T, 'U, decimal> then convPrim<_,'U> (Decimal.op_UnaryNegation(convPrim<_,decimal> value))
else UnaryOpDynamicImplTable<OpUnaryNegationInfo,'T,'U>.Invoke "op_UnaryNegation" value

let UnaryPlusDynamic<'T> (value: 'T) : 'T = value

type OpCheckedAdditionInfo = class end
let CheckedAdditionDynamic<'T1, 'T2, 'U> (x: 'T1) (y: 'T2) : 'U =
if type3eq<'T1, 'T2, 'U, int32> then convPrim<_,'U> (# "add.ovf" (convPrim<_,int32> x) (convPrim<_,int32> y) : int32 #)
Expand Down Expand Up @@ -3993,20 +3995,7 @@ namespace Microsoft.FSharp.Core

[<NoDynamicInvocation(isLegacy=true)>]
let inline (~+) (value: ^T) : ^T =
value
when ^T : int32 = value
when ^T : float = value
when ^T : float32 = value
when ^T : int64 = value
when ^T : uint64 = value
when ^T : uint32 = value
when ^T : int16 = value
when ^T : uint16 = value
when ^T : nativeint = value
when ^T : unativeint = value
when ^T : sbyte = value
when ^T : byte = value
when ^T : decimal = value
UnaryPlusDynamic<(^T)> value
when ^T : ^T = (^T: (static member (~+) : ^T -> ^T) (value))

[<NoDynamicInvocation(isLegacy=true)>]
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/FSharp.Core/prim-types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,11 @@ namespace Microsoft.FSharp.Core
[<Experimental("Experimental library feature, requires '--langversion:preview'")>]
val UnaryNegationDynamic : value:'T -> 'U

/// <summary>A compiler intrinsic that implements dynamic invocations to the unary '~+' operator.</summary>
[<CompilerMessage("This function is for use by dynamic invocations of F# code and should not be used directly", 1204, IsHidden=true)>]
[<Experimental("Experimental library feature, requires '--langversion:preview'")>]
val UnaryPlusDynamic : value:'T -> 'T

/// <summary>A compiler intrinsic that implements dynamic invocations to the '%' operator.</summary>
[<CompilerMessage("This function is for use by dynamic invocations of F# code and should not be used directly", 1204, IsHidden=true)>]
[<Experimental("Experimental library feature, requires '--langversion:preview'")>]
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,8 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
[vara], [ varaTy; v_int32_ty ], varaTy, [ arg0Ty ]
| ("GenericZeroDynamic" | "GenericOneDynamic"), [], Some retTy ->
[vara], [ ], varaTy, [ retTy ]
| "UnaryPlusDynamic", [ arg0Ty ], Some retTy ->
[vara], [ arg0Ty ], varaTy, [ retTy ]
| _ -> failwithf "unknown builtin witness '%s'" memberName
let vref = makeOtherIntrinsicValRef (fslib_MFLanguagePrimitives_nleref, memberName, None, None, gtps, (List.map List.singleton argTys, retTy))
vref, tinst
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,7 @@ Microsoft.FSharp.Core.LanguagePrimitives: TResult LogicalNotDynamic[T,TResult](T
Microsoft.FSharp.Core.LanguagePrimitives: TResult RightShiftDynamic[T1,T2,TResult](T1, T2)
Microsoft.FSharp.Core.LanguagePrimitives: TResult SubtractionDynamic[T1,T2,TResult](T1, T2)
Microsoft.FSharp.Core.LanguagePrimitives: TResult UnaryNegationDynamic[T,TResult](T)
Microsoft.FSharp.Core.LanguagePrimitives: T UnaryPlusDynamic[T](T)
Microsoft.FSharp.Core.Operators+Checked: Byte ToByte$W[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Byte], T)
Microsoft.FSharp.Core.Operators+Checked: Char ToChar$W[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Char], T)
Microsoft.FSharp.Core.Operators+Checked: Int16 ToInt16$W[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int16], T)
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,7 @@ Microsoft.FSharp.Core.LanguagePrimitives: TResult LogicalNotDynamic[T,TResult](T
Microsoft.FSharp.Core.LanguagePrimitives: TResult RightShiftDynamic[T1,T2,TResult](T1, T2)
Microsoft.FSharp.Core.LanguagePrimitives: TResult SubtractionDynamic[T1,T2,TResult](T1, T2)
Microsoft.FSharp.Core.LanguagePrimitives: TResult UnaryNegationDynamic[T,TResult](T)
Microsoft.FSharp.Core.LanguagePrimitives: T UnaryPlusDynamic[T](T)
Microsoft.FSharp.Core.Operators+Checked: Byte ToByte$W[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Byte], T)
Microsoft.FSharp.Core.Operators+Checked: Char ToChar$W[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Char], T)
Microsoft.FSharp.Core.Operators+Checked: Int16 ToInt16$W[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Int16], T)
Expand Down
43 changes: 43 additions & 0 deletions tests/fsharp/Compiler/Language/CodeQuotationTests.fs
Original file line number Diff line number Diff line change
@@ -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

[<TestFixture>]
module CodeQuotationsTests =

[<Test>]
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


25 changes: 25 additions & 0 deletions tests/fsharp/Compiler/Language/WitnessTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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

[<TestFixture>]
module WitnessTests =

[<Test>]
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


2 changes: 2 additions & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<Compile Include="Compiler\Warnings\ExperimentalAttributeTests.fs" />
<Compile Include="Compiler\Warnings\PatternMatchingWarningTests.fs" />
<Compile Include="Compiler\SourceTextTests.fs" />
<Compile Include="Compiler\Language\WitnessTests.fs" />
<Compile Include="Compiler\Language\CodeQuotationTests.fs" />
<Compile Include="Compiler\Language\CompilerDirectiveTests.fs" />
<Compile Include="Compiler\Language\DefaultInterfaceMemberTests.fs" />
<Compile Include="Compiler\Language\OptionalInteropTests.fs" />
Expand Down