diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt
index 8e827dd3fc..bb8a340e39 100644
--- a/src/fsharp/FSComp.txt
+++ b/src/fsharp/FSComp.txt
@@ -1336,3 +1336,4 @@ descriptionUnavailable,"(description unavailable...)"
3180,abImplicitHeapAllocation,"The mutable local '%s' is implicitly allocated as a reference cell because it has been captured by a closure. This warning is for informational purposes only to indicate where implicit allocations are performed."
estApplyStaticArgumentsForMethodNotImplemented,"A type provider implemented GetStaticParametersForMethod, but ApplyStaticArgumentsForMethod was not implemented or invalid"
3181,etErrorApplyingStaticArgumentsToMethod,"An error occured applying the static arguments to a provided method"
+3182,nameofNotPermitted,"This expression does not have a name."
diff --git a/src/fsharp/FSharp.Core.Unittests/FSharp.Core.Unittests.fsproj b/src/fsharp/FSharp.Core.Unittests/FSharp.Core.Unittests.fsproj
index 9cfea93607..cfdd205707 100644
--- a/src/fsharp/FSharp.Core.Unittests/FSharp.Core.Unittests.fsproj
+++ b/src/fsharp/FSharp.Core.Unittests/FSharp.Core.Unittests.fsproj
@@ -104,6 +104,7 @@
+
diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs
new file mode 100644
index 0000000000..468a3ebfae
--- /dev/null
+++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs
@@ -0,0 +1,202 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+namespace FSharp.Core.Unittests
+open System
+open NUnit.Framework
+
+[]
+type BasicNameOfTests() =
+ let localConstant = 23
+ member this.MemberMethod() = 0
+ member this.MemberProperty = this.MemberMethod()
+ static member StaticMethod() = 0
+ static member StaticProperty = BasicNameOfTests.StaticMethod()
+
+ []
+ member this.``local variable name lookup`` () =
+ let a = 0
+ let result = nameof a
+ Assert.AreEqual("a",result)
+ Assert.AreEqual("result",nameof result)
+
+ []
+ member this.``local int function name`` () =
+ let myFunction x = 0 * x
+ let b = nameof myFunction
+ Assert.AreEqual("myFunction",b)
+
+ []
+ member this.``local curried function name`` () =
+ let curriedFunction x y = x * y
+ let b = nameof curriedFunction
+ Assert.AreEqual("curriedFunction",b)
+
+ []
+ member this.``local tupled function name`` () =
+ let tupledFunction(x,y) = x * y
+ let b = nameof tupledFunction
+ Assert.AreEqual("tupledFunction",b)
+
+ []
+ member this.``local unit function name`` () =
+ let myFunction() = 1
+ let b = nameof(myFunction)
+ Assert.AreEqual("myFunction",b)
+
+ []
+ member this.``local function paarameter name`` () =
+ let myFunction parameter1 = nameof parameter1
+
+ Assert.AreEqual("parameter1",myFunction "x")
+ Assert.AreEqual("parameter1",myFunction "x")
+
+ []
+ member this.``can get name from inside a local function (needs to be let rec)`` () =
+ let rec myLocalFunction x =
+ let z = 2 * x
+ nameof myLocalFunction + " " + z.ToString()
+
+ Assert.AreEqual("myLocalFunction 46",myLocalFunction 23)
+ Assert.AreEqual("myLocalFunction 50",myLocalFunction 25)
+
+ []
+ member this.CanGetNameFromInsideAMember () =
+ let b = nameof(this.CanGetNameFromInsideAMember)
+ Assert.AreEqual("CanGetNameFromInsideAMember",b)
+
+ []
+ member this.``member function name`` () =
+ let b = nameof(this.MemberMethod)
+ Assert.AreEqual("MemberMethod",b)
+
+ []
+ member this.``member function which is defined below`` () =
+ let b = nameof(this.MemberMethodDefinedBelow)
+ Assert.AreEqual("MemberMethodDefinedBelow",b)
+
+ member this.MemberMethodDefinedBelow(x,y) = x * y
+
+ []
+ member this.``static member function name`` () =
+ let b = nameof(BasicNameOfTests.StaticMethod)
+ Assert.AreEqual("StaticMethod",b)
+
+ []
+ member this.``class member lookup`` () =
+ let b = nameof(localConstant)
+ Assert.AreEqual("localConstant",b)
+
+ []
+ member this.``member property name`` () =
+ let b = nameof(this.MemberProperty)
+ Assert.AreEqual("MemberProperty",b)
+
+ []
+ member this.``static property name`` () =
+ let b = nameof(BasicNameOfTests.StaticProperty)
+ Assert.AreEqual("StaticProperty",b)
+
+ member this.get_XYZ() = 1
+
+ []
+ member this.``member method starting with get_`` () =
+ let b = nameof(this.get_XYZ)
+ Assert.AreEqual("get_XYZ",b)
+
+ static member get_SXYZ() = 1
+
+ []
+ member this.``static method starting with get_`` () =
+ let b = nameof(BasicNameOfTests.get_SXYZ)
+ Assert.AreEqual("get_SXYZ",b)
+
+ []
+ member this.``nameof local property with encapsulated name`` () =
+ let ``local property with encapsulated name and %.f`` = 0
+ let b = nameof(``local property with encapsulated name and %.f``)
+ Assert.AreEqual("local property with encapsulated name and %.f",b)
+
+[]
+type MethodGroupTests() =
+ member this.MethodGroup() = ()
+ member this.MethodGroup(i:int) = ()
+
+ []
+ member this.``method group name lookup`` () =
+ let b = nameof(this.MethodGroup)
+ Assert.AreEqual("MethodGroup",b)
+
+[]
+type FrameworkMethodTests() =
+ []
+ member this.``library function name`` () =
+ let b = nameof(List.map)
+ Assert.AreEqual("Map",b)
+
+ []
+ member this.``static class function name`` () =
+ let b = nameof(Tuple.Create)
+ Assert.AreEqual("Create",b)
+
+[]
+type OperatorNameTests() =
+
+ []
+ member this.``lookup name of typeof operator`` () =
+ let b = nameof(typeof)
+ Assert.AreEqual("TypeOf",b)
+
+ []
+ member this.``lookup name of + operator`` () =
+ let b = nameof(+)
+ Assert.AreEqual("op_Addition",b)
+
+ []
+ member this.``lookup name of |> operator`` () =
+ let a = nameof(|>)
+ Assert.AreEqual("op_PipeRight",a)
+ let b = nameof(op_PipeRight)
+ Assert.AreEqual("op_PipeRight",b)
+
+ []
+ member this.``lookup name of nameof operator`` () =
+ let b = nameof(nameof)
+ Assert.AreEqual("NameOf",b)
+
+[]
+type PatternMatchingOfOperatorNameTests() =
+ member this.Method1(i:int) = ()
+
+ []
+ member this.``use it as a match case guard`` () =
+ match "Method1" with
+ | x when x = nameof(this.Method1) -> ()
+ | _ -> Assert.Fail("not expected")
+
+[]
+type NameOfOperatorInQuotations() =
+ []
+ member this.``use it in a quotation`` () =
+ let q =
+ <@
+ let f(x:int) = nameof x
+ f 20
+ @>
+ ()
+
+[]
+type NameOfOperatorForGenerics() =
+ []
+ member this.``use it in a generic function`` () =
+ let fullyGeneric x = x
+ let b = nameof(fullyGeneric)
+ Assert.AreEqual("fullyGeneric",b)
+
+[]
+type UserDefinedNameOfTests() =
+ []
+ member this.``userdefined nameof should shadow the operator`` () =
+ let nameof x = "test" + x.ToString()
+
+ let y = nameof 1
+ Assert.AreEqual("test1",y)
\ No newline at end of file
diff --git a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs
index 96ff2ea9b2..a0d0f4cd47 100644
--- a/src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs
+++ b/src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs
@@ -2592,6 +2592,7 @@ Microsoft.FSharp.Core.Operators: System.Object Box[T](T)" +
Microsoft.FSharp.Core.Operators: System.RuntimeMethodHandle MethodHandleOf[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult])" +
#endif
@"
+Microsoft.FSharp.Core.Operators: System.String NameOf[T](T)
Microsoft.FSharp.Core.Operators: System.String ToString()
Microsoft.FSharp.Core.Operators: System.String ToString[T](T)
Microsoft.FSharp.Core.Operators: System.String op_Concatenate(System.String, System.String)
diff --git a/src/fsharp/FSharp.Core/Linq.fs b/src/fsharp/FSharp.Core/Linq.fs
index 1156b25527..4d9bfef896 100644
--- a/src/fsharp/FSharp.Core/Linq.fs
+++ b/src/fsharp/FSharp.Core/Linq.fs
@@ -182,7 +182,7 @@ module LeafExpressionConverter =
let isFunctionType typ = equivHeadTypes typ (typeof<(int -> int)>)
let getFunctionType typ =
- if not (isFunctionType typ) then invalidArg "typ" "cannot convert recursion except for function types"
+ if not (isFunctionType typ) then invalidArg (nameof typ) "cannot convert recursion except for function types"
let tyargs = typ.GetGenericArguments()
tyargs.[0], tyargs.[1]
diff --git a/src/fsharp/FSharp.Core/Query.fs b/src/fsharp/FSharp.Core/Query.fs
index 7d7e061080..b6bdd8a10e 100644
--- a/src/fsharp/FSharp.Core/Query.fs
+++ b/src/fsharp/FSharp.Core/Query.fs
@@ -102,7 +102,7 @@ type QueryBuilder() =
and default ^Value : int>
(source: QuerySource<'T,'Q>, f : 'T -> Nullable< ^Value >) : Nullable< ^Value > =
let source = source.Source
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable acc : ^Value = LanguagePrimitives.GenericZero< (^Value) >
while e.MoveNext() do
@@ -122,7 +122,7 @@ type QueryBuilder() =
(source: QuerySource<'T,'Q>, selector: 'T -> Nullable< ^Value >) : Nullable< ^Value > =
let source = source.Source
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable acc = LanguagePrimitives.GenericZero< (^Value) >
let mutable count = 0
@@ -140,7 +140,7 @@ type QueryBuilder() =
and default ^Value : float >
(source: QuerySource<'T,'Q>, selector: 'T -> ^Value) : ^Value =
let source = source.Source
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable acc = LanguagePrimitives.GenericZero< (^U) >
let mutable count = 0
diff --git a/src/fsharp/FSharp.Core/array.fs b/src/fsharp/FSharp.Core/array.fs
index 1765606fd9..dc5da056e4 100644
--- a/src/fsharp/FSharp.Core/array.fs
+++ b/src/fsharp/FSharp.Core/array.fs
@@ -35,13 +35,13 @@ namespace Microsoft.FSharp.Collections
[]
let inline last (array : 'T[]) =
- checkNonNull "array" array
- if array.Length = 0 then invalidArg "array" InputArrayEmptyString
+ checkNonNull (nameof array) array
+ if array.Length = 0 then invalidArg (nameof array) InputArrayEmptyString
array.[array.Length-1]
[]
let tryLast (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
if array.Length = 0 then None
else Some array.[array.Length-1]
@@ -50,12 +50,12 @@ namespace Microsoft.FSharp.Collections
[]
let zeroCreate count =
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked count
[]
let create (count:int) (x:'T) =
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
let array = (Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked count : 'T[])
for i = 0 to Operators.Checked.(-) count 1 do // use checked arithmetic here to satisfy FxCop
array.[i] <- x
@@ -63,19 +63,19 @@ namespace Microsoft.FSharp.Collections
[]
let tryHead (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
if array.Length = 0 then None
else Some array.[0]
[]
let isEmpty (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
(array.Length = 0)
[]
let tail (array : 'T[]) =
- checkNonNull "array" array
- if array.Length = 0 then invalidArg "array" (SR.GetString(SR.notEnoughElements))
+ checkNonNull (nameof array) array
+ if array.Length = 0 then invalidArg (nameof array) (SR.GetString(SR.notEnoughElements))
let len = array.Length - 1
Microsoft.FSharp.Primitives.Basics.Array.subUnchecked 1 len array
@@ -85,13 +85,13 @@ namespace Microsoft.FSharp.Collections
[]
[]
let blit (source : 'T[]) sourceIndex (target: 'T[]) targetIndex count =
- checkNonNull "source" source
- checkNonNull "target" target
- if sourceIndex < 0 then invalidArg "sourceIndex" (SR.GetString(SR.inputMustBeNonNegative))
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
- if targetIndex < 0 then invalidArg "targetIndex" (SR.GetString(SR.inputMustBeNonNegative))
- if sourceIndex + count > source.Length then invalidArg "count" (SR.GetString(SR.outOfRange))
- if targetIndex + count > target.Length then invalidArg "count" (SR.GetString(SR.outOfRange))
+ checkNonNull (nameof source) source
+ checkNonNull (nameof target) target
+ if sourceIndex < 0 then invalidArg (nameof sourceIndex) (SR.GetString(SR.inputMustBeNonNegative))
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
+ if targetIndex < 0 then invalidArg (nameof targetIndex) (SR.GetString(SR.inputMustBeNonNegative))
+ if sourceIndex + count > source.Length then invalidArg (nameof count) (SR.GetString(SR.outOfRange))
+ if targetIndex + count > target.Length then invalidArg (nameof count) (SR.GetString(SR.outOfRange))
Array.Copy(source, sourceIndex, target, targetIndex, count)
// for i = 0 to count - 1 do
// target.[targetIndex+i] <- source.[sourceIndex + i]
@@ -114,14 +114,14 @@ namespace Microsoft.FSharp.Collections
[]
let concat (arrays: seq<'T[]>) =
- checkNonNull "arrays" arrays
+ checkNonNull (nameof arrays) arrays
match arrays with
| :? ('T[][]) as ts -> ts |> concatArrays // avoid a clone, since we only read the array
| _ -> arrays |> Seq.toArray |> concatArrays
[]
let replicate count x =
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
let arr = (Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked count : 'T array)
for i = 0 to count - 1 do
arr.[i] <- x
@@ -129,7 +129,7 @@ namespace Microsoft.FSharp.Collections
[]
let collect (f : 'T -> 'U[]) (array : 'T[]) : 'U[]=
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let result = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked<'U[]> len
for i = 0 to len - 1 do
@@ -138,8 +138,8 @@ namespace Microsoft.FSharp.Collections
[]
let splitAt index (array:'T[]) =
- checkNonNull "array" array
- if index < 0 then invalidArg "index" (SR.GetString(SR.inputMustBeNonNegative))
+ checkNonNull (nameof array) array
+ if index < 0 then invalidArg (nameof index) (SR.GetString(SR.inputMustBeNonNegative))
if array.Length < index then raise <| System.InvalidOperationException (SR.GetString(SR.notEnoughElements))
if index = 0 then
let right = Microsoft.FSharp.Primitives.Basics.Array.subUnchecked 0 array.Length array
@@ -155,8 +155,8 @@ namespace Microsoft.FSharp.Collections
[]
let take count (array : 'T[]) =
- checkNonNull "array" array
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ checkNonNull (nameof array) array
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
if count = 0 then empty else
if count > array.Length then
raise <| System.InvalidOperationException (SR.GetString(SR.notEnoughElements))
@@ -165,7 +165,7 @@ namespace Microsoft.FSharp.Collections
[]
let takeWhile predicate (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
if array.Length = 0 then empty else
let mutable count = 0
while count < array.Length && predicate array.[count] do
@@ -175,7 +175,7 @@ namespace Microsoft.FSharp.Collections
[]
let countBy projection (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let dict = new Dictionary,int>(Microsoft.FSharp.Core.CompilerServices.RuntimeHelpers.StructBox<'Key>.Comparer)
// Build the groupings
@@ -193,8 +193,8 @@ namespace Microsoft.FSharp.Collections
[]
let append (array1:'T[]) (array2:'T[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let n1 = array1.Length
let n2 = array2.Length
let res : 'T[] = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked (n1 + n2)
@@ -204,12 +204,12 @@ namespace Microsoft.FSharp.Collections
[]
let head (array : 'T[]) =
- checkNonNull "array" array
- if array.Length = 0 then invalidArg "array" InputArrayEmptyString else array.[0]
+ checkNonNull (nameof array) array
+ if array.Length = 0 then invalidArg (nameof array) InputArrayEmptyString else array.[0]
[]
let copy (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
(array.Clone() :?> 'T[]) // this is marginally faster
//let len = array.Length
//let res = zeroCreate len
@@ -219,17 +219,17 @@ namespace Microsoft.FSharp.Collections
[]
let toList array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.List.ofArray array
[]
let ofList list =
- checkNonNull "list" list
+ checkNonNull (nameof list) list
Microsoft.FSharp.Primitives.Basics.List.toArray list
[]
let indexed (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let res = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len
for i = 0 to len - 1 do
@@ -238,14 +238,14 @@ namespace Microsoft.FSharp.Collections
[]
let inline iter f (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
for i = 0 to len - 1 do
f array.[i]
[]
let distinct (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let temp = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked array.Length
let mutable i = 0
@@ -259,7 +259,7 @@ namespace Microsoft.FSharp.Collections
[]
let inline map (f: 'T -> 'U) (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let res = (Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len : 'U[])
for i = 0 to len - 1 do
@@ -268,17 +268,17 @@ namespace Microsoft.FSharp.Collections
[]
let iter2 f (array1: 'T[]) (array2: 'U[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let len1 = array1.Length
- if len1 <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths));
+ if len1 <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths));
for i = 0 to len1 - 1 do
f.Invoke(array1.[i], array2.[i])
[]
let distinctBy keyf (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let temp = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked array.Length
let mutable i = 0
let hashSet = HashSet<_>(HashIdentity.Structural<_>)
@@ -291,11 +291,11 @@ namespace Microsoft.FSharp.Collections
[]
let map2 f (array1: 'T[]) (array2: 'U[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let len1 = array1.Length
- if len1 <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths));
+ if len1 <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths));
let res = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len1
for i = 0 to len1 - 1 do
res.[i] <- f.Invoke(array1.[i], array2.[i])
@@ -303,9 +303,9 @@ namespace Microsoft.FSharp.Collections
[]
let map3 f (array1: 'T1[]) (array2: 'T2[]) (array3: 'T3[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
- checkNonNull "array3" array3
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
+ checkNonNull (nameof array3) array3
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
let len1 = array1.Length
if not (len1 = array2.Length && len1 = array3.Length) then invalidArg "" (SR.GetString(SR.arraysHadDifferentLengths))
@@ -317,11 +317,11 @@ namespace Microsoft.FSharp.Collections
[]
let mapi2 f (array1: 'T[]) (array2: 'U[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
let len1 = array1.Length
- if len1 <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths));
+ if len1 <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths));
let res = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len1
for i = 0 to len1 - 1 do
res.[i] <- f.Invoke(i,array1.[i], array2.[i])
@@ -329,7 +329,7 @@ namespace Microsoft.FSharp.Collections
[]
let iteri f (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let len = array.Length
for i = 0 to len - 1 do
@@ -337,17 +337,17 @@ namespace Microsoft.FSharp.Collections
[]
let iteri2 f (array1: 'T[]) (array2: 'U[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
let len1 = array1.Length
- if len1 <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths));
+ if len1 <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths));
for i = 0 to len1 - 1 do
f.Invoke(i,array1.[i], array2.[i])
[]
let mapi (f : int -> 'T -> 'U) (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let len = array.Length
let res = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len
@@ -357,24 +357,24 @@ namespace Microsoft.FSharp.Collections
[]
let mapFold<'T,'State,'Result> (f : 'State -> 'T -> 'Result * 'State) acc array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.mapFold f acc array
[]
let mapFoldBack<'T,'State,'Result> (f : 'T -> 'State -> 'Result * 'State) array acc =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.mapFoldBack f array acc
[]
let exists (f: 'T -> bool) (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let rec loop i = i < len && (f array.[i] || loop (i+1))
loop 0
[]
let inline contains e (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let mutable state = false
let mutable i = 0
while (not state && i < array.Length) do
@@ -384,34 +384,34 @@ namespace Microsoft.FSharp.Collections
[]
let exists2 f (array1: _[]) (array2: _[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let len1 = array1.Length
- if len1 <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths))
+ if len1 <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths))
let rec loop i = i < len1 && (f.Invoke(array1.[i], array2.[i]) || loop (i+1))
loop 0
[]
let forall (f: 'T -> bool) (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let rec loop i = i >= len || (f array.[i] && loop (i+1))
loop 0
[]
let forall2 f (array1: _[]) (array2: _[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let len1 = array1.Length
- if len1 <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths))
+ if len1 <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths))
let rec loop i = i >= len1 || (f.Invoke(array1.[i], array2.[i]) && loop (i+1))
loop 0
[]
let groupBy keyf (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let dict = new Dictionary,ResizeArray<'T>>(RuntimeHelpers.StructBox<'Key>.Comparer)
// Build the groupings
@@ -437,7 +437,7 @@ namespace Microsoft.FSharp.Collections
[]
let pick f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let rec loop i =
if i >= array.Length then
indexNotFound()
@@ -449,7 +449,7 @@ namespace Microsoft.FSharp.Collections
[]
let tryPick f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let rec loop i =
if i >= array.Length then None else
match f array.[i] with
@@ -459,7 +459,7 @@ namespace Microsoft.FSharp.Collections
[]
let choose f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let res = new System.Collections.Generic.List<_>() // ResizeArray
for i = 0 to array.Length - 1 do
match f array.[i] with
@@ -469,7 +469,7 @@ namespace Microsoft.FSharp.Collections
[]
let filter f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let res = new System.Collections.Generic.List<_>() // ResizeArray
for i = 0 to array.Length - 1 do
let x = array.[i]
@@ -481,7 +481,7 @@ namespace Microsoft.FSharp.Collections
[]
let partition f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let res1 = new System.Collections.Generic.List<_>() // ResizeArray
let res2 = new System.Collections.Generic.List<_>() // ResizeArray
for i = 0 to array.Length - 1 do
@@ -491,7 +491,7 @@ namespace Microsoft.FSharp.Collections
[]
let find f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let rec loop i =
if i >= array.Length then indexNotFound() else
if f array.[i] then array.[i] else loop (i+1)
@@ -499,7 +499,7 @@ namespace Microsoft.FSharp.Collections
[]
let tryFind f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let rec loop i =
if i >= array.Length then None else
if f array.[i] then Some array.[i] else loop (i+1)
@@ -507,8 +507,8 @@ namespace Microsoft.FSharp.Collections
[]
let skip count (array:'T[]) =
- checkNonNull "array" array
- if count > array.Length then invalidArg "count" (SR.GetString(SR.outOfRange))
+ checkNonNull (nameof array) array
+ if count > array.Length then invalidArg (nameof count) (SR.GetString(SR.outOfRange))
if count = array.Length then
[| |]
else
@@ -517,7 +517,7 @@ namespace Microsoft.FSharp.Collections
[]
let skipWhile p (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let mutable i = 0
let len = array.Length
while i < len && p array.[i] do i <- i + 1
@@ -529,28 +529,28 @@ namespace Microsoft.FSharp.Collections
[]
let findBack f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.findBack f array
[]
let tryFindBack f (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.tryFindBack f array
[]
let findIndexBack f (array : _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.findIndexBack f array
[]
let tryFindIndexBack f (array : _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.tryFindIndexBack f array
[]
let windowed windowSize (array:'T[]) =
- checkNonNull "array" array
- if windowSize <= 0 then invalidArg "windowSize" (SR.GetString(SR.inputMustBeNonNegative))
+ checkNonNull (nameof array) array
+ if windowSize <= 0 then invalidArg (nameof windowSize) (SR.GetString(SR.inputMustBeNonNegative))
let len = array.Length
if windowSize > len then
[| |]
@@ -562,10 +562,10 @@ namespace Microsoft.FSharp.Collections
[]
let zip (array1: _[]) (array2: _[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let len1 = array1.Length
- if len1 <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths))
+ if len1 <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths))
let res = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len1
for i = 0 to len1 - 1 do
res.[i] <- (array1.[i],array2.[i])
@@ -573,12 +573,12 @@ namespace Microsoft.FSharp.Collections
[]
let zip3 (array1: _[]) (array2: _[]) (array3: _[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
- checkNonNull "array3" array3
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
+ checkNonNull (nameof array3) array3
let len1 = array1.Length
- if len1 <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths))
- if len1 <> array3.Length then invalidArg "array3" (SR.GetString(SR.arraysHadDifferentLengths))
+ if len1 <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths))
+ if len1 <> array3.Length then invalidArg (nameof array3) (SR.GetString(SR.arraysHadDifferentLengths))
let res = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len1
for i = 0 to len1 - 1 do
res.[i] <- (array1.[i],array2.[i],array3.[i])
@@ -598,7 +598,7 @@ namespace Microsoft.FSharp.Collections
[]
let unzip (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let res1 = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len
let res2 = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len
@@ -610,7 +610,7 @@ namespace Microsoft.FSharp.Collections
[]
let unzip3 (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let res1 = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len
let res2 = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len
@@ -624,7 +624,7 @@ namespace Microsoft.FSharp.Collections
[]
let rev (array: _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let res = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len
for i = 0 to len - 1 do
@@ -633,7 +633,7 @@ namespace Microsoft.FSharp.Collections
[]
let fold<'T,'State> (f : 'State -> 'T -> 'State) (acc: 'State) (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable state = acc
let len = array.Length
@@ -643,7 +643,7 @@ namespace Microsoft.FSharp.Collections
[]
let foldBack<'T,'State> (f : 'T -> 'State -> 'State) (array:'T[]) (acc: 'State) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable res = acc
let len = array.Length
@@ -654,31 +654,31 @@ namespace Microsoft.FSharp.Collections
[]
let foldBack2<'T1,'T2,'State> f (array1:'T1[]) (array2:'T2 []) (acc: 'State) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
let mutable res = acc
let len = array1.Length
- if len <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths))
+ if len <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths))
for i = len - 1 downto 0 do
res <- f.Invoke(array1.[i],array2.[i],res)
res
[]
let fold2<'T1,'T2,'State> f (acc: 'State) (array1:'T1[]) (array2:'T2 []) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
let mutable state = acc
let len = array1.Length
- if len <> array2.Length then invalidArg "array2" (SR.GetString(SR.arraysHadDifferentLengths))
+ if len <> array2.Length then invalidArg (nameof array2) (SR.GetString(SR.arraysHadDifferentLengths))
for i = 0 to len - 1 do
state <- f.Invoke(state,array1.[i],array2.[i])
state
let foldSubRight f (array : _[]) start fin acc =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable res = acc
for i = fin downto start do
@@ -686,7 +686,7 @@ namespace Microsoft.FSharp.Collections
res
let scanSubLeft f initState (array : _[]) start fin =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable state = initState
let res = create (2+fin-start) initState
@@ -697,13 +697,13 @@ namespace Microsoft.FSharp.Collections
[]
let scan<'T,'State> f (acc:'State) (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
scanSubLeft f acc array 0 (len - 1)
[]
let scanBack<'T,'State> f (array : 'T[]) (acc:'State) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.scanSubRight f array 0 (array.Length - 1) acc
[]
@@ -711,15 +711,15 @@ namespace Microsoft.FSharp.Collections
[]
let pairwise (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
if array.Length < 2 then [||] else
init (array.Length-1) (fun i -> array.[i],array.[i+1])
[]
let reduce f (array : _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
- if len = 0 then invalidArg "array" InputArrayEmptyString else
+ if len = 0 then invalidArg (nameof array) InputArrayEmptyString else
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable res = array.[0]
for i = 1 to len - 1 do
@@ -728,14 +728,14 @@ namespace Microsoft.FSharp.Collections
[]
let reduceBack f (array : _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
- if len = 0 then invalidArg "array" InputArrayEmptyString
+ if len = 0 then invalidArg (nameof array) InputArrayEmptyString
else foldSubRight f array 0 (len - 2) array.[len - 1]
[]
let sortInPlaceWith f (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
if len < 2 then ()
elif len = 2 then
@@ -749,60 +749,60 @@ namespace Microsoft.FSharp.Collections
[]
let sortInPlaceBy (f: 'T -> 'U) (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.unstableSortInPlaceBy f array
[]
let sortInPlace (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.unstableSortInPlace array
[]
let sortWith (f: 'T -> 'T -> int) (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let result = copy array
sortInPlaceWith f result;
result
[]
let sortBy f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let result = copy array
sortInPlaceBy f result;
result
[]
let sort array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let result = copy array
sortInPlace result;
result
[]
let inline sortByDescending f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let inline compareDescending a b = compare (f b) (f a)
sortWith compareDescending array
[]
let inline sortDescending array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let inline compareDescending a b = compare b a
sortWith compareDescending array
[]
let toSeq array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Seq.ofArray array
[]
let ofSeq source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
Seq.toArray source
[]
let findIndex f (array : _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let rec go n =
if n >= len then
@@ -814,19 +814,19 @@ namespace Microsoft.FSharp.Collections
[]
let tryFindIndex f (array : _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len = array.Length
let rec go n = if n >= len then None elif f array.[n] then Some n else go (n+1)
go 0
[]
let permute p (array : _[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Microsoft.FSharp.Primitives.Basics.Array.permute p array
[]
let inline sum (array: (^T)[] ) : ^T =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let mutable acc = LanguagePrimitives.GenericZero< (^T) >
for i = 0 to array.Length - 1 do
acc <- Checked.(+) acc array.[i]
@@ -834,7 +834,7 @@ namespace Microsoft.FSharp.Collections
[]
let inline sumBy (f: 'T -> ^U) (array:'T[]) : ^U =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let mutable acc = LanguagePrimitives.GenericZero< (^U) >
for i = 0 to array.Length - 1 do
acc <- Checked.(+) acc (f array.[i])
@@ -842,8 +842,8 @@ namespace Microsoft.FSharp.Collections
[]
let inline min (array:_[]) =
- checkNonNull "array" array
- if array.Length = 0 then invalidArg "array" InputArrayEmptyString
+ checkNonNull (nameof array) array
+ if array.Length = 0 then invalidArg (nameof array) InputArrayEmptyString
let mutable acc = array.[0]
for i = 1 to array.Length - 1 do
let curr = array.[i]
@@ -853,8 +853,8 @@ namespace Microsoft.FSharp.Collections
[]
let inline minBy f (array:_[]) =
- checkNonNull "array" array
- if array.Length = 0 then invalidArg "array" InputArrayEmptyString
+ checkNonNull (nameof array) array
+ if array.Length = 0 then invalidArg (nameof array) InputArrayEmptyString
let mutable accv = array.[0]
let mutable acc = f accv
for i = 1 to array.Length - 1 do
@@ -867,8 +867,8 @@ namespace Microsoft.FSharp.Collections
[]
let inline max (array:_[]) =
- checkNonNull "array" array
- if array.Length = 0 then invalidArg "array" InputArrayEmptyString
+ checkNonNull (nameof array) array
+ if array.Length = 0 then invalidArg (nameof array) InputArrayEmptyString
let mutable acc = array.[0]
for i = 1 to array.Length - 1 do
let curr = array.[i]
@@ -878,8 +878,8 @@ namespace Microsoft.FSharp.Collections
[]
let inline maxBy f (array:_[]) =
- checkNonNull "array" array
- if array.Length = 0 then invalidArg "array" InputArrayEmptyString
+ checkNonNull (nameof array) array
+ if array.Length = 0 then invalidArg (nameof array) InputArrayEmptyString
let mutable accv = array.[0]
let mutable acc = f accv
for i = 1 to array.Length - 1 do
@@ -892,18 +892,18 @@ namespace Microsoft.FSharp.Collections
[]
let inline average (array:_[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Seq.average array
[]
let inline averageBy f (array:_[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Seq.averageBy f array
[]
let inline compareWith (comparer:'T -> 'T -> int) (array1: 'T[]) (array2: 'T[]) =
- checkNonNull "array1" array1
- checkNonNull "array2" array2
+ checkNonNull (nameof array1) array1
+ checkNonNull (nameof array2) array2
let length1 = array1.Length
let length2 = array2.Length
@@ -923,10 +923,10 @@ namespace Microsoft.FSharp.Collections
[]
let sub (array:'T[]) (startIndex:int) (count:int) =
- checkNonNull "array" array
- if startIndex < 0 then invalidArg "startIndex" (SR.GetString(SR.inputMustBeNonNegative))
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
- if startIndex + count > array.Length then invalidArg "count" (SR.GetString(SR.outOfRange))
+ checkNonNull (nameof array) array
+ if startIndex < 0 then invalidArg (nameof startIndex) (SR.GetString(SR.inputMustBeNonNegative))
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
+ if startIndex + count > array.Length then invalidArg (nameof count) (SR.GetString(SR.outOfRange))
Microsoft.FSharp.Primitives.Basics.Array.subUnchecked startIndex count array
[]
@@ -935,7 +935,7 @@ namespace Microsoft.FSharp.Collections
[]
let tryItem index (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
if index < 0 || index >= array.Length then None
else Some(array.[index])
@@ -949,23 +949,23 @@ namespace Microsoft.FSharp.Collections
[]
let fill (target:'T[]) (targetIndex:int) (count:int) (x:'T) =
- checkNonNull "target" target
- if targetIndex < 0 then invalidArg "targetIndex" (SR.GetString(SR.inputMustBeNonNegative))
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ checkNonNull (nameof target) target
+ if targetIndex < 0 then invalidArg (nameof targetIndex) (SR.GetString(SR.inputMustBeNonNegative))
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
for i = targetIndex to targetIndex + count - 1 do
target.[i] <- x
[]
let exactlyOne (array:'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
if array.Length = 1 then array.[0]
- elif array.Length = 0 then invalidArg "array" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString
- else invalidArg "array" (SR.GetString(SR.inputSequenceTooLong))
+ elif array.Length = 0 then invalidArg (nameof array) LanguagePrimitives.ErrorStrings.InputSequenceEmptyString
+ else invalidArg (nameof array) (SR.GetString(SR.inputSequenceTooLong))
[]
let truncate count (array:'T[]) =
- checkNonNull "array" array
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ checkNonNull (nameof array) array
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
if count = 0 then empty
else
let len = array.Length
@@ -979,7 +979,7 @@ namespace Microsoft.FSharp.Collections
[]
let choose f (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let inputLength = array.Length
let lastInputIndex = inputLength - 1
@@ -1009,7 +1009,7 @@ namespace Microsoft.FSharp.Collections
[]
let collect (f : 'T -> 'U[]) (array : 'T[]) : 'U[]=
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let inputLength = array.Length
let result = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked inputLength
Parallel.For(0, inputLength,
@@ -1018,7 +1018,7 @@ namespace Microsoft.FSharp.Collections
[]
let map (f: 'T -> 'U) (array : 'T[]) : 'U[]=
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let inputLength = array.Length
let result = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked inputLength
Parallel.For(0, inputLength, fun i ->
@@ -1027,7 +1027,7 @@ namespace Microsoft.FSharp.Collections
[]
let mapi f (array: 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let inputLength = array.Length
let result = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked inputLength
@@ -1037,12 +1037,12 @@ namespace Microsoft.FSharp.Collections
[]
let iter f (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
Parallel.For (0, array.Length, fun i -> f array.[i]) |> ignore
[]
let iteri f (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
Parallel.For (0, array.Length, fun i -> f.Invoke(i, array.[i])) |> ignore
@@ -1054,7 +1054,7 @@ namespace Microsoft.FSharp.Collections
[]
let partition predicate (array : 'T[]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let inputLength = array.Length
let lastInputIndex = inputLength - 1
diff --git a/src/fsharp/FSharp.Core/array2.fs b/src/fsharp/FSharp.Core/array2.fs
index 10af4df8ce..8717793a7a 100644
--- a/src/fsharp/FSharp.Core/array2.fs
+++ b/src/fsharp/FSharp.Core/array2.fs
@@ -87,7 +87,7 @@ namespace Microsoft.FSharp.Collections
[]
let iter f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let count1 = length1 array
let count2 = length2 array
let b1 = base1 array
@@ -98,7 +98,7 @@ namespace Microsoft.FSharp.Collections
[]
let iteri (f : int -> int -> 'T -> unit) (array:'T[,]) =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let count1 = length1 array
let count2 = length2 array
let b1 = base1 array
@@ -110,31 +110,31 @@ namespace Microsoft.FSharp.Collections
[]
let map f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
initBased (base1 array) (base2 array) (length1 array) (length2 array) (fun i j -> f array.[i,j])
[]
let mapi f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
initBased (base1 array) (base2 array) (length1 array) (length2 array) (fun i j -> f.Invoke(i, j, array.[i,j]))
[]
let copy array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
initBased (base1 array) (base2 array) (length1 array) (length2 array) (fun i j -> array.[i,j])
[]
let rebase array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let b1 = base1 array
let b2 = base2 array
init (length1 array) (length2 array) (fun i j -> array.[b1+i,b2+j])
[]
let blit (source : 'T[,]) sourceIndex1 sourceIndex2 (target : 'T[,]) targetIndex1 targetIndex2 count1 count2 =
- checkNonNull "source" source
- checkNonNull "target" target
+ checkNonNull (nameof source) source
+ checkNonNull (nameof target) target
if sourceIndex1 < source.GetLowerBound(0) then invalidArg "sourceIndex1" (SR.GetString(SR.outOfRange))
if sourceIndex2 < source.GetLowerBound(1) then invalidArg "sourceIndex2" (SR.GetString(SR.outOfRange))
if targetIndex1 < target.GetLowerBound(0) then invalidArg "targetIndex1" (SR.GetString(SR.outOfRange))
diff --git a/src/fsharp/FSharp.Core/array3.fs b/src/fsharp/FSharp.Core/array3.fs
index 6f930c7af9..b7c68980e3 100644
--- a/src/fsharp/FSharp.Core/array3.fs
+++ b/src/fsharp/FSharp.Core/array3.fs
@@ -61,7 +61,7 @@ namespace Microsoft.FSharp.Collections
[]
let iter f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
@@ -72,7 +72,7 @@ namespace Microsoft.FSharp.Collections
[]
let map f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
@@ -85,7 +85,7 @@ namespace Microsoft.FSharp.Collections
[]
let iteri f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
@@ -97,7 +97,7 @@ namespace Microsoft.FSharp.Collections
[]
let mapi f array =
- checkNonNull "array" array
+ checkNonNull (nameof array) array
let len1 = length1 array
let len2 = length2 array
let len3 = length3 array
diff --git a/src/fsharp/FSharp.Core/math/n.fs b/src/fsharp/FSharp.Core/math/n.fs
index 09b779b9de..348308c21e 100644
--- a/src/fsharp/FSharp.Core/math/n.fs
+++ b/src/fsharp/FSharp.Core/math/n.fs
@@ -1551,7 +1551,7 @@ module internal BigNatModule =
let ofString (str:string) =
// Would it be better to split string half and combine results?
let len = str.Length
- if System.String.IsNullOrEmpty str then invalidArg "str" "empty string";
+ if System.String.IsNullOrEmpty str then invalidArg (nameof str) "empty string";
let ten = embed 10
let rec build acc i =
if i=len then
diff --git a/src/fsharp/FSharp.Core/math/z.fs b/src/fsharp/FSharp.Core/math/z.fs
index 6cdce310cf..13083f15e5 100644
--- a/src/fsharp/FSharp.Core/math/z.fs
+++ b/src/fsharp/FSharp.Core/math/z.fs
@@ -60,7 +60,7 @@ namespace System.Numerics
| 0, -1 -> BigNatModule.isZero y.V
| 1, 0 -> BigNatModule.isZero x.V
| -1, 0 -> BigNatModule.isZero x.V
- | _ -> invalidArg "x" "signs should be +/- 1 or 0"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1 or 0"
static member op_Inequality (x:BigInteger, y:BigInteger) = not (BigInteger.op_Equality(x,y)) // CA2226: OperatorsShouldHaveSymmetricalOverloads
@@ -79,7 +79,7 @@ namespace System.Numerics
| 0,-1 -> false
| 1, 0 -> false
| -1, 0 -> not (BigNatModule.isZero x.V)
- | _ -> invalidArg "x" "signs should be +/- 1 or 0"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1 or 0"
static member op_GreaterThan (x:BigInteger, y:BigInteger) = // Follow lt by +/- symmetry
match x.SignInt,y.SignInt with
@@ -92,7 +92,7 @@ namespace System.Numerics
| 0,-1 -> not (BigNatModule.isZero y.V)
| 1, 0 -> not (BigNatModule.isZero x.V)
| -1, 0 -> false
- | _ -> invalidArg "x" "signs should be +/- 1 or 0"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1 or 0"
static member internal compare(n,nn) = if BigInteger.op_LessThan(n,nn) then -1 elif BigInteger.op_Equality(n,nn) then 0 else 1
@@ -116,7 +116,7 @@ namespace System.Numerics
member this.CompareTo(obj:obj) =
match obj with
| :? BigInteger as that -> BigInteger.compare(this,that)
- | _ -> invalidArg "obj" "the objects are not comparable"
+ | _ -> invalidArg (nameof obj) "the objects are not comparable"
override this.Equals(obj) =
match obj with
@@ -175,7 +175,7 @@ namespace System.Numerics
| -1,-1 -> -(BigInteger.addnn(x.V,y.V)) // -1.xv + -1.yv = -(xv + yv)
| 1,-1 -> BigInteger.subnn (x.V,y.V) // 1.xv + -1.yv = (xv - yv)
| -1, 1 -> BigInteger.subnn(y.V,x.V) // -1.xv + 1.yv = (yv - xv)
- | _ -> invalidArg "x" "signs should be +/- 1"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1"
static member (-) (x:BigInteger,y:BigInteger) =
if y.IsZero then x else
@@ -185,7 +185,7 @@ namespace System.Numerics
| -1,-1 -> BigInteger.subnn(y.V,x.V) // -1.xv - -1.yv = (yv - xv)
| 1,-1 -> BigInteger.addnn(x.V,y.V) // 1.xv - -1.yv = (xv + yv)
| -1, 1 -> -(BigInteger.addnn(x.V,y.V)) // -1.xv - 1.yv = -(xv + yv)
- | _ -> invalidArg "x" "signs should be +/- 1"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1"
static member ( * ) (x:BigInteger,y:BigInteger) =
if x.IsZero then x
@@ -210,7 +210,7 @@ namespace System.Numerics
| -1,-1 -> rem <- BigInteger.negn r ; BigInteger.posn d // -1.xv = 1.d.(-1.yv) + (-1.r)
| 1,-1 -> rem <- BigInteger.posn r ; BigInteger.negn d // 1.xv = -1.d.(-1.yv) + ( 1.r)
| -1, 1 -> rem <- BigInteger.negn r ; BigInteger.negn d // -1.xv = -1.d.( 1.yv) + (-1.r)
- | _ -> invalidArg "x" "signs should be +/- 1"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1"
static member (/) (x:BigInteger,y:BigInteger) =
let mutable rem = new BigInteger(0)
@@ -247,7 +247,7 @@ namespace System.Numerics
| -1, 0 -> true
| 0, 1 -> true
| 0,-1 -> BigNatModule.isZero y.V
- | _ -> invalidArg "x" "signs should be +/- 1 or 0"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1 or 0"
static member op_GreaterThanOrEqual (x:BigInteger,y:BigInteger) = // Follow lte by +/- symmetry
match x.SignInt,y.SignInt with
@@ -260,7 +260,7 @@ namespace System.Numerics
| -1, 0 -> BigNatModule.isZero x.V
| 0, 1 -> BigNatModule.isZero y.V
| 0,-1 -> true
- | _ -> invalidArg "x" "signs should be +/- 1 or 0"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1 or 0"
static member Pow (x:BigInteger,y:int32) =
if y < 0 then raise (new System.ArgumentOutOfRangeException("y", (SR.GetString(SR.inputMustBeNonNegative))))
@@ -302,10 +302,10 @@ namespace System.Numerics
| 1 -> BigNatModule.toFloat x.V // float (1.xv) = float (xv)
| -1 -> - (BigNatModule.toFloat x.V) // float (-1.xv) = - float (xv)
| 0 -> 0.
- | _ -> invalidArg "x" "signs should be +/- 1 or 0"
+ | _ -> invalidArg (nameof x) "signs should be +/- 1 or 0"
static member Parse(text:string) =
- if text = null then raise (new ArgumentNullException("text"))
+ if text = null then raise (new ArgumentNullException(nameof(text)))
let text = text.Trim()
let len = text.Length
if len = 0 then raise (new System.FormatException(SR.GetString(SR.badFormatString)))
@@ -319,7 +319,7 @@ namespace System.Numerics
member internal x.IsSmall = x.IsZero || BigNatModule.isSmall (x.V)
static member Factorial (x:BigInteger) =
- if x.IsNegative then invalidArg "x" (SR.GetString(SR.inputMustBeNonNegative))
+ if x.IsNegative then invalidArg (nameof x) (SR.GetString(SR.inputMustBeNonNegative))
if x.IsPositive then BigInteger.posn (BigNatModule.factorial x.V)
else BigInteger.One
diff --git a/src/fsharp/FSharp.Core/prim-types.fs b/src/fsharp/FSharp.Core/prim-types.fs
index 2fc6ada882..059abe2071 100644
--- a/src/fsharp/FSharp.Core/prim-types.fs
+++ b/src/fsharp/FSharp.Core/prim-types.fs
@@ -4715,6 +4715,9 @@ namespace Microsoft.FSharp.Core
[]
let inline typeof<'T> = BasicInlinedOperations.typeof<'T>
+ []
+ let inline nameof (_: 'T) : string = raise (Exception "may not call directly, should always be optimized away")
+
[]
let methodhandleof (_call: ('T -> 'TResult)) : System.RuntimeMethodHandle = raise (Exception "may not call directly, should always be optimized away")
diff --git a/src/fsharp/FSharp.Core/prim-types.fsi b/src/fsharp/FSharp.Core/prim-types.fsi
index dc8ee26bfd..4c6274ed09 100644
--- a/src/fsharp/FSharp.Core/prim-types.fsi
+++ b/src/fsharp/FSharp.Core/prim-types.fsi
@@ -2292,6 +2292,10 @@ namespace Microsoft.FSharp.Core
[]
val inline typeof<'T> : System.Type
+ /// Returns the name of the given symbol.
+ []
+ val inline nameof : 'T -> string
+
/// An internal, library-only compiler intrinsic for compile-time
/// generation of a RuntimeMethodHandle.
[]
diff --git a/src/fsharp/FSharp.Core/quotations.fs b/src/fsharp/FSharp.Core/quotations.fs
index 93240a7ad6..255ef3a829 100644
--- a/src/fsharp/FSharp.Core/quotations.fs
+++ b/src/fsharp/FSharp.Core/quotations.fs
@@ -2028,7 +2028,7 @@ module DerivedPatterns =
Some(obj,(minfo2.GetGenericArguments() |> Array.toList),args)
| _ -> None)
| _ ->
- invalidArg "templateParameter" (SR.GetString(SR.QunrecognizedMethodCall))
+ invalidArg (nameof templateParameter) (SR.GetString(SR.QunrecognizedMethodCall))
let private new_decimal_info =
methodhandleof (fun (low, medium, high, isNegative, scale) -> LanguagePrimitives.IntrinsicFunctions.MakeDecimal low medium high isNegative scale)
diff --git a/src/fsharp/FSharp.Core/seq.fs b/src/fsharp/FSharp.Core/seq.fs
index 66a64984ad..70d03bed69 100644
--- a/src/fsharp/FSharp.Core/seq.fs
+++ b/src/fsharp/FSharp.Core/seq.fs
@@ -64,7 +64,7 @@ namespace Microsoft.FSharp.Collections
else tryItem (index-1) e
let rec nth index (e : IEnumerator<'T>) =
- if not (e.MoveNext()) then invalidArg "index" (SR.GetString(SR.notEnoughElements))
+ if not (e.MoveNext()) then invalidArg (nameof index) (SR.GetString(SR.notEnoughElements))
if index = 0 then e.Current
else nth (index-1) e
@@ -896,26 +896,26 @@ namespace Microsoft.FSharp.Collections
[]
let init count f =
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
mkSeq (fun () -> IEnumerator.upto (Some (count-1)) f)
[]
let iter f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
while e.MoveNext() do
f e.Current;
[]
- let item i (source : seq<'T>) =
- checkNonNull "source" source
- if i < 0 then invalidArg "index" (SR.GetString(SR.inputMustBeNonNegative))
+ let item index (source : seq<'T>) =
+ checkNonNull (nameof source) source
+ if index < 0 then invalidArg (nameof index) (SR.GetString(SR.inputMustBeNonNegative))
use e = source.GetEnumerator()
- IEnumerator.nth i e
+ IEnumerator.nth index e
[]
let tryItem i (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
if i < 0 then None else
use e = source.GetEnumerator()
IEnumerator.tryItem i e
@@ -925,7 +925,7 @@ namespace Microsoft.FSharp.Collections
[]
let iteri f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable i = 0
@@ -935,7 +935,7 @@ namespace Microsoft.FSharp.Collections
[]
let exists f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable state = false
while (not state && e.MoveNext()) do
@@ -944,7 +944,7 @@ namespace Microsoft.FSharp.Collections
[]
let inline contains element (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable state = false
while (not state && e.MoveNext()) do
@@ -953,7 +953,7 @@ namespace Microsoft.FSharp.Collections
[]
let forall f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable state = true
while (state && e.MoveNext()) do
@@ -963,8 +963,8 @@ namespace Microsoft.FSharp.Collections
[]
let iter2 f (source1 : seq<_>) (source2 : seq<_>) =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
use e1 = source1.GetEnumerator()
use e2 = source2.GetEnumerator()
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
@@ -973,8 +973,8 @@ namespace Microsoft.FSharp.Collections
[]
let iteri2 f (source1 : seq<_>) (source2 : seq<_>) =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
use e1 = source1.GetEnumerator()
use e2 = source2.GetEnumerator()
let f = OptimizedClosures.FSharpFunc<_,_,_,_>.Adapt(f)
@@ -992,7 +992,7 @@ namespace Microsoft.FSharp.Collections
[]
let filter f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
revamp (IEnumerator.filter f) source
[]
@@ -1000,64 +1000,64 @@ namespace Microsoft.FSharp.Collections
[]
let map f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
revamp (IEnumerator.map f) source
[]
let mapi f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
revamp (IEnumerator.mapi f) source
[]
let mapi2 f source1 source2 =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
revamp2 (IEnumerator.mapi2 f) source1 source2
[]
let map2 f source1 source2 =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
revamp2 (IEnumerator.map2 f) source1 source2
[]
let map3 f source1 source2 source3 =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
- checkNonNull "source3" source3
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
+ checkNonNull (nameof source3) source3
revamp3 (IEnumerator.map3 f) source1 source2 source3
[]
let choose f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
revamp (IEnumerator.choose f) source
[]
let indexed source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mapi (fun i x -> i,x) source
[]
let zip source1 source2 =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
map2 (fun x y -> x,y) source1 source2
[]
let zip3 source1 source2 source3 =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
- checkNonNull "source3" source3
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
+ checkNonNull (nameof source3) source3
map2 (fun x (y,z) -> x,y,z) source1 (zip source2 source3)
[]
let cast (source: IEnumerable) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkSeq (fun () -> IEnumerator.cast (source.GetEnumerator()))
[]
let tryPick f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable res = None
while (Option.isNone res && e.MoveNext()) do
@@ -1066,14 +1066,14 @@ namespace Microsoft.FSharp.Collections
[]
let pick f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
match tryPick f source with
| None -> indexNotFound()
| Some x -> x
[]
let tryFind f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable res = None
while (Option.isNone res && e.MoveNext()) do
@@ -1083,15 +1083,15 @@ namespace Microsoft.FSharp.Collections
[]
let find f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
match tryFind f source with
| None -> indexNotFound()
| Some x -> x
[]
let take count (source : seq<'T>) =
- checkNonNull "source" source
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ checkNonNull (nameof source) source
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
(* Note: don't create or dispose any IEnumerable if n = 0 *)
if count = 0 then empty else
seq { use e = source.GetEnumerator()
@@ -1102,7 +1102,7 @@ namespace Microsoft.FSharp.Collections
[]
let isEmpty (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
match source with
| :? ('T[]) as a -> a.Length = 0
| :? list<'T> as a -> a.IsEmpty
@@ -1114,12 +1114,12 @@ namespace Microsoft.FSharp.Collections
[]
let concat sources =
- checkNonNull "sources" sources
+ checkNonNull (nameof sources) sources
mkConcatSeq sources
[]
let length (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
match source with
| :? ('T[]) as a -> a.Length
| :? ('T list) as a -> a.Length
@@ -1133,7 +1133,7 @@ namespace Microsoft.FSharp.Collections
[]
let fold<'T,'State> f (x:'State) (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable state = x
@@ -1143,8 +1143,8 @@ namespace Microsoft.FSharp.Collections
[]
let fold2<'T1,'T2,'State> f (state:'State) (source1: seq<'T1>) (source2: seq<'T2>) =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
use e1 = source1.GetEnumerator()
use e2 = source2.GetEnumerator()
@@ -1159,9 +1159,9 @@ namespace Microsoft.FSharp.Collections
[]
let reduce f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
- if not (e.MoveNext()) then invalidArg "source" InputSequenceEmptyString;
+ if not (e.MoveNext()) then invalidArg (nameof source) InputSequenceEmptyString;
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let mutable state = e.Current
while e.MoveNext() do
@@ -1176,15 +1176,15 @@ namespace Microsoft.FSharp.Collections
#if FX_ATLEAST_40
System.Linq.Enumerable.Repeat(x,count)
#else
- if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative))
+ if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative))
seq { for _ in 1 .. count -> x }
#endif
[]
let append (source1: seq<'T>) (source2: seq<'T>) =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
fromGenerator(fun () -> Generator.bindG (toGenerator source1) (fun () -> toGenerator source2))
@@ -1193,8 +1193,8 @@ namespace Microsoft.FSharp.Collections
[]
let compareWith (f:'T -> 'T -> int) (source1 : seq<'T>) (source2: seq<'T>) =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
use e1 = source1.GetEnumerator()
use e2 = source2.GetEnumerator()
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
@@ -1216,18 +1216,18 @@ namespace Microsoft.FSharp.Collections
[]
let toList (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
Microsoft.FSharp.Primitives.Basics.List.ofSeq source
// Create a new object to ensure underlying array may not be mutated by a backdoor cast
[]
let ofArray (source : 'T array) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkSeq (fun () -> IEnumerator.ofArray source)
[]
let toArray (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
match source with
| :? ('T[]) as res -> (res.Clone() :?> 'T[])
| :? ('T list) as res -> List.toArray res
@@ -1249,7 +1249,7 @@ namespace Microsoft.FSharp.Collections
[]
let foldBack<'T,'State> f (source : seq<'T>) (x:'State) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
let arr = toArray source
let len = arr.Length
@@ -1262,10 +1262,10 @@ namespace Microsoft.FSharp.Collections
[]
let reduceBack f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
let arr = toArray source
match arr.Length with
- | 0 -> invalidArg "source" InputSequenceEmptyString
+ | 0 -> invalidArg (nameof source) InputSequenceEmptyString
| len ->
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
foldArraySubRight f arr 0 (len - 2) arr.[len - 1]
@@ -1276,7 +1276,7 @@ namespace Microsoft.FSharp.Collections
[]
let truncate n (source: seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
seq { let i = ref 0
use ie = source.GetEnumerator()
while !i < n && ie.MoveNext() do
@@ -1285,7 +1285,7 @@ namespace Microsoft.FSharp.Collections
[]
let pairwise (source: seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
seq { use ie = source.GetEnumerator()
if ie.MoveNext() then
let iref = ref ie.Current
@@ -1296,7 +1296,7 @@ namespace Microsoft.FSharp.Collections
[]
let scan<'T,'State> f (z:'State) (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
seq { let zref = ref z
yield !zref
@@ -1307,17 +1307,17 @@ namespace Microsoft.FSharp.Collections
[]
let tryFindBack f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
source |> toArray |> Array.tryFindBack f
[]
let findBack f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
source |> toArray |> Array.findBack f
[]
let scanBack<'T,'State> f (source : seq<'T>) (acc:'State) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkDelayedSeq(fun () ->
let arr = source |> toArray
let res = Array.scanSubRight f arr 0 (arr.Length - 1) acc
@@ -1325,7 +1325,7 @@ namespace Microsoft.FSharp.Collections
[]
let findIndex p (source:seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use ie = source.GetEnumerator()
let rec loop i =
if ie.MoveNext() then
@@ -1338,7 +1338,7 @@ namespace Microsoft.FSharp.Collections
[]
let tryFindIndex p (source:seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use ie = source.GetEnumerator()
let rec loop i =
if ie.MoveNext() then
@@ -1351,19 +1351,19 @@ namespace Microsoft.FSharp.Collections
[]
let tryFindIndexBack f (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
source |> toArray |> Array.tryFindIndexBack f
[]
let findIndexBack f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
source |> toArray |> Array.findIndexBack f
// windowed : int -> seq<'T> -> seq<'T[]>
[]
let windowed windowSize (source: seq<_>) =
- checkNonNull "source" source
- if windowSize <= 0 then invalidArg "windowSize" (SR.GetString(SR.inputMustBeNonNegative))
+ checkNonNull (nameof source) source
+ if windowSize <= 0 then invalidArg (nameof windowSize) (SR.GetString(SR.inputMustBeNonNegative))
seq {
let arr = Array.zeroCreateUnchecked windowSize
let r = ref (windowSize - 1)
@@ -1385,7 +1385,7 @@ namespace Microsoft.FSharp.Collections
[]
let cache (source : seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
// Wrap a seq to ensure that it is enumerated just once and only as far as is necessary.
//
// This code is required to be thread safe.
@@ -1442,7 +1442,7 @@ namespace Microsoft.FSharp.Collections
[]
[]
let readonly (source:seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkSeq (fun () -> source.GetEnumerator())
@@ -1474,7 +1474,7 @@ namespace Microsoft.FSharp.Collections
[]
let distinct source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
seq { let hashSet = HashSet<'T>(HashIdentity.Structural<'T>)
for v in source do
if hashSet.Add(v) then
@@ -1482,7 +1482,7 @@ namespace Microsoft.FSharp.Collections
[]
let distinctBy keyf source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
seq { let hashSet = HashSet<_>(HashIdentity.Structural<_>)
for v in source do
if hashSet.Add(keyf v) then
@@ -1490,7 +1490,7 @@ namespace Microsoft.FSharp.Collections
[]
let sortBy keyf source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkDelayedSeq (fun () ->
let array = source |> toArray
Array.stableSortInPlaceBy keyf array
@@ -1498,7 +1498,7 @@ namespace Microsoft.FSharp.Collections
[]
let sort source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkDelayedSeq (fun () ->
let array = source |> toArray
Array.stableSortInPlace array
@@ -1506,7 +1506,7 @@ namespace Microsoft.FSharp.Collections
[]
let sortWith f source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkDelayedSeq (fun () ->
let array = source |> toArray
Array.stableSortInPlaceWith f array
@@ -1514,19 +1514,19 @@ namespace Microsoft.FSharp.Collections
[]
let inline sortByDescending keyf source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
let inline compareDescending a b = compare (keyf b) (keyf a)
sortWith compareDescending source
[]
let inline sortDescending source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
let inline compareDescending a b = compare b a
sortWith compareDescending source
[]
let countBy keyf source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkDelayedSeq (fun () ->
let dict = new Dictionary,int>(StructBox<'Key>.Comparer)
@@ -1556,7 +1556,7 @@ namespace Microsoft.FSharp.Collections
[]
let inline average (source: seq< (^a) >) : ^a =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable acc = LanguagePrimitives.GenericZero< (^a) >
let mutable count = 0
@@ -1564,12 +1564,12 @@ namespace Microsoft.FSharp.Collections
acc <- Checked.(+) acc e.Current
count <- count + 1
if count = 0 then
- invalidArg "source" InputSequenceEmptyString
+ invalidArg (nameof source) InputSequenceEmptyString
LanguagePrimitives.DivideByInt< (^a) > acc count
[]
let inline averageBy (f : 'T -> ^U) (source: seq< 'T >) : ^U =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
let mutable acc = LanguagePrimitives.GenericZero< (^U) >
let mutable count = 0
@@ -1577,15 +1577,15 @@ namespace Microsoft.FSharp.Collections
acc <- Checked.(+) acc (f e.Current)
count <- count + 1
if count = 0 then
- invalidArg "source" InputSequenceEmptyString;
+ invalidArg (nameof source) InputSequenceEmptyString;
LanguagePrimitives.DivideByInt< (^U) > acc count
[]
let inline min (source: seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
- invalidArg "source" InputSequenceEmptyString;
+ invalidArg (nameof source) InputSequenceEmptyString;
let mutable acc = e.Current
while e.MoveNext() do
let curr = e.Current
@@ -1595,10 +1595,10 @@ namespace Microsoft.FSharp.Collections
[]
let inline minBy (f : 'T -> 'U) (source: seq<'T>) : 'T =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
- invalidArg "source" InputSequenceEmptyString;
+ invalidArg (nameof source) InputSequenceEmptyString;
let first = e.Current
let mutable acc = f first
let mutable accv = first
@@ -1613,10 +1613,10 @@ namespace Microsoft.FSharp.Collections
(*
[]
let inline minValBy (f : 'T -> 'U) (source: seq<'T>) : 'U =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
- invalidArg "source" InputSequenceEmptyString;
+ invalidArg (nameof source) InputSequenceEmptyString;
let first = e.Current
let mutable acc = f first
while e.MoveNext() do
@@ -1629,10 +1629,10 @@ namespace Microsoft.FSharp.Collections
*)
[]
let inline max (source: seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
- invalidArg "source" InputSequenceEmptyString;
+ invalidArg (nameof source) InputSequenceEmptyString;
let mutable acc = e.Current
while e.MoveNext() do
let curr = e.Current
@@ -1642,10 +1642,10 @@ namespace Microsoft.FSharp.Collections
[]
let inline maxBy (f : 'T -> 'U) (source: seq<'T>) : 'T =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
- invalidArg "source" InputSequenceEmptyString;
+ invalidArg (nameof source) InputSequenceEmptyString;
let first = e.Current
let mutable acc = f first
let mutable accv = first
@@ -1661,10 +1661,10 @@ namespace Microsoft.FSharp.Collections
(*
[]
let inline maxValBy (f : 'T -> 'U) (source: seq<'T>) : 'U =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if not (e.MoveNext()) then
- invalidArg "source" InputSequenceEmptyString;
+ invalidArg (nameof source) InputSequenceEmptyString;
let first = e.Current
let mutable acc = f first
while e.MoveNext() do
@@ -1677,7 +1677,7 @@ namespace Microsoft.FSharp.Collections
*)
[]
let takeWhile p (source: seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
seq { use e = source.GetEnumerator()
let latest = ref Unchecked.defaultof<_>
while e.MoveNext() && (latest := e.Current; p !latest) do
@@ -1685,7 +1685,7 @@ namespace Microsoft.FSharp.Collections
[]
let skip count (source: seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
seq { use e = source.GetEnumerator()
for _ in 1 .. count do
if not (e.MoveNext()) then
@@ -1695,7 +1695,7 @@ namespace Microsoft.FSharp.Collections
[]
let skipWhile p (source: seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
seq { use e = source.GetEnumerator()
let latest = ref (Unchecked.defaultof<_>)
let ok = ref false
@@ -1707,8 +1707,8 @@ namespace Microsoft.FSharp.Collections
[]
let forall2 p (source1: seq<_>) (source2: seq<_>) =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
use e1 = source1.GetEnumerator()
use e2 = source2.GetEnumerator()
let p = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(p)
@@ -1720,8 +1720,8 @@ namespace Microsoft.FSharp.Collections
[]
let exists2 p (source1: seq<_>) (source2: seq<_>) =
- checkNonNull "source1" source1
- checkNonNull "source2" source2
+ checkNonNull (nameof source1) source1
+ checkNonNull (nameof source2) source2
use e1 = source1.GetEnumerator()
use e2 = source2.GetEnumerator()
let p = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(p)
@@ -1732,41 +1732,41 @@ namespace Microsoft.FSharp.Collections
[]
let head (source : seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if (e.MoveNext()) then e.Current
- else invalidArg "source" InputSequenceEmptyString
+ else invalidArg (nameof source) InputSequenceEmptyString
[]
let tryHead (source : seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if (e.MoveNext()) then Some e.Current
else None
[]
let tail (source: seq<'T>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
seq { use e = source.GetEnumerator()
if not (e.MoveNext()) then
- invalidArg "source" (SR.GetString(SR.notEnoughElements))
+ invalidArg (nameof source) (SR.GetString(SR.notEnoughElements))
while e.MoveNext() do
yield e.Current }
[]
let last (source : seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if e.MoveNext() then
let mutable res = e.Current
while (e.MoveNext()) do res <- e.Current
res
else
- invalidArg "source" InputSequenceEmptyString
+ invalidArg (nameof source) InputSequenceEmptyString
[]
let tryLast (source : seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if e.MoveNext() then
let mutable res = e.Current
@@ -1777,20 +1777,20 @@ namespace Microsoft.FSharp.Collections
[]
let exactlyOne (source : seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
use e = source.GetEnumerator()
if e.MoveNext() then
let v = e.Current
if e.MoveNext() then
- invalidArg "source" (SR.GetString(SR.inputSequenceTooLong))
+ invalidArg (nameof source) (SR.GetString(SR.inputSequenceTooLong))
else
v
else
- invalidArg "source" InputSequenceEmptyString
+ invalidArg (nameof source) InputSequenceEmptyString
[]
let rev source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkDelayedSeq (fun () ->
let array = source |> toArray
Array.Reverse array
@@ -1798,19 +1798,19 @@ namespace Microsoft.FSharp.Collections
[]
let permute f (source : seq<_>) =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
mkDelayedSeq (fun () ->
source |> toArray |> Array.permute f :> seq<_>)
[]
let mapFold<'T,'State,'Result> (f: 'State -> 'T -> 'Result * 'State) acc source =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
let arr,state = source |> toArray |> Array.mapFold f acc
readonly arr, state
[]
let mapFoldBack<'T,'State,'Result> (f: 'T -> 'State -> 'Result * 'State) source acc =
- checkNonNull "source" source
+ checkNonNull (nameof source) source
let array = source |> toArray
let arr,state = Array.mapFoldBack f array acc
readonly arr, state
diff --git a/src/fsharp/check.fs b/src/fsharp/check.fs
index 08ae499e85..ebf81552bd 100644
--- a/src/fsharp/check.fs
+++ b/src/fsharp/check.fs
@@ -425,6 +425,30 @@ let CheckMultipleInterfaceInstantiations cenv interfaces m =
| Some (typ1,typ2) ->
errorR(Error(FSComp.SR.chkMultipleGenericInterfaceInstantiations((NicePrint.minimalStringOfType cenv.denv typ1), (NicePrint.minimalStringOfType cenv.denv typ2)),m))
+// tries to extract the name of an expression
+let extractNameOf args =
+ match args with
+ | [expr] ->
+ match expr with
+ | Expr.Val(r,_,_) -> Some(r.CompiledName)
+ | Expr.App(Expr.Val(r,_,_),_,_,Expr.Const(constant,_,_)::_,_) ->
+ if r.CompiledName.StartsWith("get_") && constant = Const.Unit then // TODO: We need a better way to find static property getters
+ Some(r.CompiledName.Substring(4))
+ else
+ None // the function was applied
+ | Expr.App(Expr.Val(r,_,_),_,_,[],_) -> Some(r.CompiledName)
+ | Expr.App(Expr.Val(r,_,_),_,_,_,_) ->
+ if r.CompiledName.StartsWith("get_") then // TODO: We need a better way to find member property getters
+ Some(r.CompiledName.Substring(4))
+ else
+ None // the function was applied
+ | Expr.Let(_,Expr.Val(r,_,_),_,_) -> Some(r.CompiledName)
+ | Expr.Let(_,Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_),_,_) -> Some(r.CompiledName)
+ | Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_) -> Some(r.CompiledName)
+ | Expr.Op(TOp.ValFieldGet(r),_,_,_) -> Some(r.FieldName)
+ | Expr.Lambda(_,_,_,_,Expr.Op(TOp.ILCall(_,_,_,_,_,_,_,r,_,_,_),_,_,_),_,_) -> Some(r.Name)
+ | _ -> None
+ | _ -> None
let rec CheckExpr (cenv:cenv) (env:env) expr =
CheckExprInContext cenv env expr GeneralContext
@@ -456,6 +480,10 @@ and CheckExprInContext (cenv:cenv) (env:env) expr (context:ByrefCallContext) =
CheckExpr cenv env body
| Expr.Const (_,m,ty) ->
CheckTypePermitByrefs cenv m ty
+
+ | Expr.App(Expr.Val (v,_,_),_,_,args,m) ->
+ if cenv.reportErrors && valRefEq cenv.g v cenv.g.nameof_vref && extractNameOf args = None then
+ errorR(Error(FSComp.SR.nameofNotPermitted(), m))
| Expr.Val (v,vFlags,m) ->
if cenv.reportErrors then
diff --git a/src/fsharp/check.fsi b/src/fsharp/check.fsi
index b0c3ac8cf0..76e28a4964 100644
--- a/src/fsharp/check.fsi
+++ b/src/fsharp/check.fsi
@@ -7,3 +7,4 @@ open Microsoft.FSharp.Compiler
val testFlagMemberBody : bool ref
val CheckTopImpl : Env.TcGlobals * Import.ImportMap * bool * Infos.InfoReader * Tast.CompilationPath list * Tast.CcuThunk * Tastops.DisplayEnv * Tast.ModuleOrNamespaceExprWithSig * Tast.Attribs * bool -> bool
+val extractNameOf : Microsoft.FSharp.Compiler.Tast.Expr list -> string option
\ No newline at end of file
diff --git a/src/fsharp/env.fs b/src/fsharp/env.fs
index 9916987068..b7f5896af0 100644
--- a/src/fsharp/env.fs
+++ b/src/fsharp/env.fs
@@ -421,6 +421,8 @@ type public TcGlobals =
reraise_vref : ValRef;
typeof_info : IntrinsicValRef;
typeof_vref : ValRef;
+ nameof_info : IntrinsicValRef;
+ nameof_vref : ValRef;
methodhandleof_info : IntrinsicValRef;
methodhandleof_vref : ValRef;
sizeof_vref : ValRef;
@@ -908,6 +910,7 @@ let mkTcGlobals (compilingFslib,sysCcu,ilg,fslibCcu,directoryToResolveRelativePa
let raise_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "raise" ,None ,Some "Raise" ,[vara],([[mkSysNonGenericTy sys "Exception"]],varaTy))
let reraise_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "reraise" ,None ,Some "Reraise",[vara], ([[unit_ty]],varaTy))
let typeof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "typeof" ,None ,Some "TypeOf" ,[vara], ([],system_Type_typ))
+ let nameof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "nameof" ,None ,Some "NameOf" ,[vara], ([[varaTy]],string_ty))
let methodhandleof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "methodhandleof" ,None ,Some "MethodHandleOf",[vara;varb],([[varaTy --> varbTy]],system_RuntimeMethodHandle_typ))
let sizeof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "sizeof" ,None ,Some "SizeOf" ,[vara], ([],int_ty))
let unchecked_defaultof_info = makeIntrinsicValRef(fslib_MFOperatorsUnchecked_nleref, "defaultof" ,None ,Some "DefaultOf",[vara], ([],varaTy))
@@ -1344,6 +1347,8 @@ let mkTcGlobals (compilingFslib,sysCcu,ilg,fslibCcu,directoryToResolveRelativePa
reraise_vref = ValRefForIntrinsic reraise_info;
methodhandleof_info = methodhandleof_info;
methodhandleof_vref = ValRefForIntrinsic methodhandleof_info;
+ nameof_info = nameof_info;
+ nameof_vref = ValRefForIntrinsic nameof_info;
typeof_info = typeof_info;
typeof_vref = ValRefForIntrinsic typeof_info;
sizeof_vref = ValRefForIntrinsic sizeof_info;
diff --git a/src/fsharp/opt.fs b/src/fsharp/opt.fs
index 0bbe956408..8ac59aa218 100644
--- a/src/fsharp/opt.fs
+++ b/src/fsharp/opt.fs
@@ -1200,7 +1200,7 @@ let AbstractAndRemapModulInfo msg g m (repackage,hidden) info =
info
//-------------------------------------------------------------------------
-// Misc helerps
+// Misc helpers
//-------------------------------------------------------------------------
// Mark some variables (the ones we introduce via abstractBigTargets) as don't-eliminate
@@ -1854,7 +1854,7 @@ and OptimizeExprOpFallback cenv env (op,tyargs,args',m) arginfos valu =
let cost,valu =
match op with
| TOp.UnionCase c -> 2,MakeValueInfoForUnionCase c (Array.ofList argValues)
- | TOp.ExnConstr _ -> 2,valu (* REVIEW: information collection possilbe here *)
+ | TOp.ExnConstr _ -> 2,valu (* REVIEW: information collection possible here *)
| TOp.Tuple -> 1, MakeValueInfoForTuple (Array.ofList argValues)
| TOp.ValFieldGet _
| TOp.TupleFieldGet _
@@ -2491,6 +2491,17 @@ and TryDevirtualizeApplication cenv env (f,tyargs,args,m) =
MightMakeCriticalTailcall = false;
Info=UnknownValue})
+ // Analyze the name of the given symbol and rewrite AST to constant string expression with the name
+ | Expr.Val(vref,_,_),_,_ when valRefEq cenv.g vref cenv.g.nameof_vref ->
+ match PostTypecheckSemanticChecks.extractNameOf args with
+ | Some name ->
+ Some( Expr.Const(Const.String name,m,cenv.g.string_ty),
+ { TotalSize=1;
+ FunctionSize=1
+ HasEffect=false;
+ MightMakeCriticalTailcall = false;
+ Info=UnknownValue})
+ | _ -> None
| _ -> None
/// Attempt to inline an application of a known value at callsites
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAdditionExpr.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAdditionExpr.fs
new file mode 100644
index 0000000000..0bd01cf99a
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAdditionExpr.fs
@@ -0,0 +1,7 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on const string
+//This expression does not have a name.
+
+let x = nameof(1+2)
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAppliedFunction.fs
new file mode 100644
index 0000000000..c75278d544
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAppliedFunction.fs
@@ -0,0 +1,8 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on applied functions
+//This expression does not have a name.
+
+let f() = 1
+let x = nameof(f())
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAsAFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAsAFunction.fs
new file mode 100644
index 0000000000..2c0b400849
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAsAFunction.fs
@@ -0,0 +1,7 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on dictionary lookup
+//This expression does not have a name.
+
+let f = nameof
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfDictLookup.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfDictLookup.fs
new file mode 100644
index 0000000000..d3c2b3f1b3
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfDictLookup.fs
@@ -0,0 +1,8 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on dictionary lookup
+//This expression does not have a name.
+
+let dict = new System.Collections.Generic.Dictionary()
+let b = nameof(dict.[2])
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntConst.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntConst.fs
new file mode 100644
index 0000000000..f3296ee474
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntConst.fs
@@ -0,0 +1,7 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on const int
+//This expression does not have a name.
+
+let x = nameof 1
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntegerAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntegerAppliedFunction.fs
new file mode 100644
index 0000000000..8b574a31e9
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntegerAppliedFunction.fs
@@ -0,0 +1,8 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on applied functions
+//This expression does not have a name.
+
+let f x = 1 * x
+let x = nameof(f 2)
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfParameterAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfParameterAppliedFunction.fs
new file mode 100644
index 0000000000..489d0af27d
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfParameterAppliedFunction.fs
@@ -0,0 +1,9 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on applied functions
+//This expression does not have a name.
+
+let f x y = x y
+let z x = 1 * x
+let b = nameof(f z 1)
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfPartiallyAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfPartiallyAppliedFunction.fs
new file mode 100644
index 0000000000..843fb70ff4
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfPartiallyAppliedFunction.fs
@@ -0,0 +1,8 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on applied functions
+//This expression does not have a name.
+
+let f x y = y * x
+let x = nameof(f 2)
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfStringConst.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfStringConst.fs
new file mode 100644
index 0000000000..1ba2ce42d3
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfStringConst.fs
@@ -0,0 +1,7 @@
+// #Regression #Conformance #DataExpressions
+// Verify that nameof doesn't work on const string
+//This expression does not have a name.
+
+let x = nameof "string"
+
+exit 0
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst
new file mode 100644
index 0000000000..449a4114be
--- /dev/null
+++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst
@@ -0,0 +1,9 @@
+ SOURCE=E_NameOfIntConst.fs # E_NameOfIntConst.fs
+ SOURCE=E_NameOfStringConst.fs # E_NameOfStringConst.fs
+ SOURCE=E_NameOfAppliedFunction.fs # E_NameOfAppliedFunction.fs
+ SOURCE=E_NameOfIntegerAppliedFunction.fs # E_NameOfIntegerAppliedFunction.fs
+ SOURCE=E_NameOfPartiallyAppliedFunction.fs # E_NameOfPartiallyAppliedFunction.fs
+ SOURCE=E_NameOfDictLookup.fs # E_NameOfDictLookup.fs
+ SOURCE=E_NameOfAdditionExpr.fs # E_NameOfAdditionExpr.fs
+ SOURCE=E_NameOfParameterAppliedFunction.fs # E_NameOfParameterAppliedFunction.fs
+ SOURCE=E_NameOfAsAFunction.fs # E_NameOfAsAFunction.fs
\ No newline at end of file
diff --git a/tests/fsharpqa/Source/test.lst b/tests/fsharpqa/Source/test.lst
index 637176988b..50bd2dc22b 100644
--- a/tests/fsharpqa/Source/test.lst
+++ b/tests/fsharpqa/Source/test.lst
@@ -235,7 +235,7 @@ Conformance08 Conformance\UnitsOfMeasure\Parenthesis
Conformance08 Conformance\UnitsOfMeasure\Parsing
Conformance08 Conformance\UnitsOfMeasure\TypeChecker
Conformance08 Conformance\UnitsOfMeasure\WithOOP
-
+Conformance08 Conformance\Expressions\DataExpressions\NameOf
NoHostedCompiler,TypeProviders01 TypeProviders\Arrays
NoHostedCompiler,TypeProviders01 ..\..\..\testsprivate\fsharpqa\Source\TypeProviders\BuiltIn\EdmxFile