From fbc332821c923816a860c6af57dbde7ec1c33725 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 15 Nov 2014 19:33:53 +0100 Subject: [PATCH 01/21] Implementing basic nameof scenarios --- src/fsharp/FSComp.txt | 1 + .../FSharp.Core.Unittests.fsproj | 1 + .../FSharp.Core.Unittests/NameOfTests.fs | 82 +++++++++++++++++++ .../FSharp.Core.Unittests/SurfaceArea.4.0.fs | 1 + src/fsharp/FSharp.Core/prim-types.fs | 3 + src/fsharp/FSharp.Core/prim-types.fsi | 4 + src/fsharp/check.fs | 13 +++ src/fsharp/env.fs | 5 ++ src/fsharp/opt.fs | 23 +++++- 9 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 src/fsharp/FSharp.Core.Unittests/NameOfTests.fs 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..6adda21a35 --- /dev/null +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -0,0 +1,82 @@ +// 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 function name`` () = + let myFunction x = 0 * x + 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.``static member function name`` () = + let b = nameof(BasicNameOfTests.StaticMethod) + Assert.AreEqual("StaticMethod",b) + + [] + 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) + + [] + 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("get_MemberProperty",b) + + [] + member this.``static property name`` () = + let b = nameof(BasicNameOfTests.StaticProperty) + Assert.AreEqual("get_StaticProperty",b) \ 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/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/check.fs b/src/fsharp/check.fs index 08ae499e85..8f705901cd 100644 --- a/src/fsharp/check.fs +++ b/src/fsharp/check.fs @@ -456,6 +456,19 @@ 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 then + if valRefEq cenv.g v cenv.g.nameof_vref then + match args with + | [Expr.Val(_,_,_)] + | [Expr.App(Expr.Val(_,_,_),_,_,_,_)] + | [Expr.Let(_,Expr.Val(_,_,_),_,_)] + | [Expr.Let(_,Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(_,_,_),_,_,_,_),_,_),_,_)] + | [Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(_,_,_),_,_,_,_),_,_)] + | [Expr.Op(TOp.ValFieldGet(_),_,_,_)] + | [Expr.Lambda(_,_,_,_,Expr.Op(TOp.ILCall(_,_,_,_,_,_,_,_,_,_,_),_,_,_),_,_)] -> () + | _ -> errorR(Error(FSComp.SR.nameofNotPermitted(), m)) | Expr.Val (v,vFlags,m) -> if cenv.reportErrors then 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..20e762e6ca 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,25 @@ and TryDevirtualizeApplication cenv env (f,tyargs,args,m) = MightMakeCriticalTailcall = false; Info=UnknownValue}) + // Analyze the name of the given symbol + | Expr.Val(vref,_,_),_,_ when valRefEq cenv.g vref cenv.g.nameof_vref -> + let name = + match args.Head with + | Expr.Val(r,_,_) -> r.CompiledName + | Expr.App(Expr.Val(r,_,_),_,_,_,_) -> r.CompiledName + | Expr.Let(_,Expr.Val(r,_,_),_,_) -> r.CompiledName + | Expr.Let(_,Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_),_,_) -> r.CompiledName + | Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_) -> r.CompiledName + | Expr.Op(TOp.ValFieldGet(r),_,_,_) -> r.FieldName + | Expr.Lambda(_,_,_,_,Expr.Op(TOp.ILCall(_,_,_,_,_,_,_,r,_,_,_),_,_,_),_,_) -> r.Name + | _ -> "unknown value" + + Some( Expr.Const(Const.String name,m,cenv.g.string_ty), + { TotalSize=1; + FunctionSize=1 + HasEffect=false; + MightMakeCriticalTailcall = false; + Info=UnknownValue}) | _ -> None /// Attempt to inline an application of a known value at callsites From 8fde5edaa31ee9a61713202343b065f8b05043e0 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sun, 16 Nov 2014 12:01:41 +0100 Subject: [PATCH 02/21] Use the same function for check.fs and opt.fs --- src/fsharp/check.fs | 27 ++++++++++++++++----------- src/fsharp/check.fsi | 1 + src/fsharp/opt.fs | 28 ++++++++++------------------ 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/fsharp/check.fs b/src/fsharp/check.fs index 8f705901cd..f31e7d0782 100644 --- a/src/fsharp/check.fs +++ b/src/fsharp/check.fs @@ -425,6 +425,20 @@ 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:Exprs) = + match args with + | [expr] -> + match expr with + | Expr.Val(r,_,_) -> Some r.CompiledName + | Expr.App(Expr.Val(r,_,_),_,_,_,_) -> Some r.CompiledName + | 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 @@ -458,17 +472,8 @@ and CheckExprInContext (cenv:cenv) (env:env) expr (context:ByrefCallContext) = CheckTypePermitByrefs cenv m ty | Expr.App(Expr.Val (v,_,_),_,_,args,m) -> - if cenv.reportErrors then - if valRefEq cenv.g v cenv.g.nameof_vref then - match args with - | [Expr.Val(_,_,_)] - | [Expr.App(Expr.Val(_,_,_),_,_,_,_)] - | [Expr.Let(_,Expr.Val(_,_,_),_,_)] - | [Expr.Let(_,Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(_,_,_),_,_,_,_),_,_),_,_)] - | [Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(_,_,_),_,_,_,_),_,_)] - | [Expr.Op(TOp.ValFieldGet(_),_,_,_)] - | [Expr.Lambda(_,_,_,_,Expr.Op(TOp.ILCall(_,_,_,_,_,_,_,_,_,_,_),_,_,_),_,_)] -> () - | _ -> errorR(Error(FSComp.SR.nameofNotPermitted(), 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..3fc0791bcc 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 : Exprs -> string \ No newline at end of file diff --git a/src/fsharp/opt.fs b/src/fsharp/opt.fs index 20e762e6ca..cac35150b8 100644 --- a/src/fsharp/opt.fs +++ b/src/fsharp/opt.fs @@ -2491,25 +2491,17 @@ and TryDevirtualizeApplication cenv env (f,tyargs,args,m) = MightMakeCriticalTailcall = false; Info=UnknownValue}) - // Analyze the name of the given symbol + // Analyze the name of the given symbol and rewrite AST to constant string expression wth the name | Expr.Val(vref,_,_),_,_ when valRefEq cenv.g vref cenv.g.nameof_vref -> - let name = - match args.Head with - | Expr.Val(r,_,_) -> r.CompiledName - | Expr.App(Expr.Val(r,_,_),_,_,_,_) -> r.CompiledName - | Expr.Let(_,Expr.Val(r,_,_),_,_) -> r.CompiledName - | Expr.Let(_,Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_),_,_) -> r.CompiledName - | Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_) -> r.CompiledName - | Expr.Op(TOp.ValFieldGet(r),_,_,_) -> r.FieldName - | Expr.Lambda(_,_,_,_,Expr.Op(TOp.ILCall(_,_,_,_,_,_,_,r,_,_,_),_,_,_),_,_) -> r.Name - | _ -> "unknown value" - - Some( Expr.Const(Const.String name,m,cenv.g.string_ty), - { TotalSize=1; - FunctionSize=1 - HasEffect=false; - MightMakeCriticalTailcall = false; - Info=UnknownValue}) + 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 From 1dea9a76f9ad781cc65b36f3a221452ea87bd76e Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sun, 16 Nov 2014 12:21:10 +0100 Subject: [PATCH 03/21] Fix check.fs types --- src/fsharp/check.fs | 2 +- src/fsharp/check.fsi | 2 +- src/fsharp/opt.fs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fsharp/check.fs b/src/fsharp/check.fs index f31e7d0782..9ad07ab48b 100644 --- a/src/fsharp/check.fs +++ b/src/fsharp/check.fs @@ -426,7 +426,7 @@ let CheckMultipleInterfaceInstantiations cenv interfaces m = 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:Exprs) = +let extractNameOf args = match args with | [expr] -> match expr with diff --git a/src/fsharp/check.fsi b/src/fsharp/check.fsi index 3fc0791bcc..76e28a4964 100644 --- a/src/fsharp/check.fsi +++ b/src/fsharp/check.fsi @@ -7,4 +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 : Exprs -> string \ No newline at end of file +val extractNameOf : Microsoft.FSharp.Compiler.Tast.Expr list -> string option \ No newline at end of file diff --git a/src/fsharp/opt.fs b/src/fsharp/opt.fs index cac35150b8..8ac59aa218 100644 --- a/src/fsharp/opt.fs +++ b/src/fsharp/opt.fs @@ -2491,8 +2491,8 @@ 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 wth the name - | Expr.Val(vref,_,_),_,_ when valRefEq cenv.g vref cenv.g.nameof_vref -> + // 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), From 4d143aa36a592362df20eb4157f14ecd8b963bfe Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sun, 16 Nov 2014 15:23:01 +0100 Subject: [PATCH 04/21] Add QA tests which show expected compile errors --- .../Expressions/DataExpressions/NameOf/NameOfIntConst.fs | 7 +++++++ .../DataExpressions/NameOf/NameOfStringConst.fs | 7 +++++++ .../Conformance/Expressions/DataExpressions/NameOf/env.lst | 2 ++ tests/fsharpqa/Source/test.lst | 1 + 4 files changed, 17 insertions(+) create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntConst.fs create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfStringConst.fs create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntConst.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntConst.fs new file mode 100644 index 0000000000..f3296ee474 --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/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/NameOfStringConst.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfStringConst.fs new file mode 100644 index 0000000000..5ce07d83c3 --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfStringConst.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 "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..7d7ab0a9e8 --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst @@ -0,0 +1,2 @@ + SOURCE=NameOfIntConst.fs # NameOfIntConst.fs + SOURCE=NameOfStringConst.fs # NameOfStringConst.fs \ No newline at end of file diff --git a/tests/fsharpqa/Source/test.lst b/tests/fsharpqa/Source/test.lst index 637176988b..cfdb6a864d 100644 --- a/tests/fsharpqa/Source/test.lst +++ b/tests/fsharpqa/Source/test.lst @@ -236,6 +236,7 @@ Conformance08 Conformance\UnitsOfMeasure\Parsing Conformance08 Conformance\UnitsOfMeasure\TypeChecker Conformance08 Conformance\UnitsOfMeasure\WithOOP +Conformance09 Conformance\Expressions\DataExpressions\NameOf NoHostedCompiler,TypeProviders01 TypeProviders\Arrays NoHostedCompiler,TypeProviders01 ..\..\..\testsprivate\fsharpqa\Source\TypeProviders\BuiltIn\EdmxFile From 8b89dde7eacec15d8239f2d4c36d15236f65f74e Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sun, 16 Nov 2014 16:13:22 +0100 Subject: [PATCH 05/21] Add more unit tests --- src/fsharp/FSharp.Core.Unittests/NameOfTests.fs | 16 +++++++++++++++- .../Expressions/DataExpressions/NameOf/env.lst | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 6adda21a35..bc9aa57a26 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -79,4 +79,18 @@ type BasicNameOfTests() = [] member this.``static property name`` () = let b = nameof(BasicNameOfTests.StaticProperty) - Assert.AreEqual("get_StaticProperty",b) \ No newline at end of file + Assert.AreEqual("get_StaticProperty",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) + + member this.MethodGroup() = () + member this.MethodGroup(i:int) = () + + [] + member this.``method group name lookup`` () = + let b = nameof(this.MethodGroup) + Assert.AreEqual("MethodGroup",b) \ 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 index 7d7ab0a9e8..40ccb5360b 100644 --- a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst @@ -1,2 +1,2 @@ SOURCE=NameOfIntConst.fs # NameOfIntConst.fs - SOURCE=NameOfStringConst.fs # NameOfStringConst.fs \ No newline at end of file + SOURCE=NameOfStringConst.fs # NameOfStringConst.fs \ No newline at end of file From 2fd949849e8c1212d41c02c25af035ccf2f9caa4 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 17 Nov 2014 10:13:42 +0100 Subject: [PATCH 06/21] Don't allow to use nameof on applied or partially applied functions --- .../FSharp.Core.Unittests/NameOfTests.fs | 20 ++++++++++++++++++- src/fsharp/check.fs | 5 +++++ .../NameOf/NameOfAppliedFunction.fs | 8 ++++++++ .../NameOf/NameOfIntegerAppliedFunction.fs | 8 ++++++++ .../NameOf/NameOfPartiallyAppliedFunction.fs | 8 ++++++++ .../NameOf/NameOfStringConst.fs | 2 +- .../DataExpressions/NameOf/env.lst | 5 ++++- 7 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAppliedFunction.fs create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntegerAppliedFunction.fs create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfPartiallyAppliedFunction.fs diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index bc9aa57a26..8a78965097 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -20,11 +20,29 @@ type BasicNameOfTests() = Assert.AreEqual("result",nameof result) [] - member this.``local function name`` () = + 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 diff --git a/src/fsharp/check.fs b/src/fsharp/check.fs index 9ad07ab48b..48bb48b15b 100644 --- a/src/fsharp/check.fs +++ b/src/fsharp/check.fs @@ -431,6 +431,11 @@ let extractNameOf args = | [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 property getters + Some r.CompiledName + else + None // the function was applied | Expr.App(Expr.Val(r,_,_),_,_,_,_) -> Some r.CompiledName | Expr.Let(_,Expr.Val(r,_,_),_,_) -> Some r.CompiledName | Expr.Let(_,Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_),_,_) -> Some r.CompiledName diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAppliedFunction.fs new file mode 100644 index 0000000000..c75278d544 --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/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/NameOfIntegerAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntegerAppliedFunction.fs new file mode 100644 index 0000000000..8b574a31e9 --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/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/NameOfPartiallyAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfPartiallyAppliedFunction.fs new file mode 100644 index 0000000000..843fb70ff4 --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/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/NameOfStringConst.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfStringConst.fs index 5ce07d83c3..1ba2ce42d3 100644 --- a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfStringConst.fs +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfStringConst.fs @@ -1,5 +1,5 @@ // #Regression #Conformance #DataExpressions -// Verify that nameof doesn't work on const int +// Verify that nameof doesn't work on const string //This expression does not have a name. let x = nameof "string" diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst index 40ccb5360b..97b034ae0d 100644 --- a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst @@ -1,2 +1,5 @@ SOURCE=NameOfIntConst.fs # NameOfIntConst.fs - SOURCE=NameOfStringConst.fs # NameOfStringConst.fs \ No newline at end of file + SOURCE=NameOfStringConst.fs # NameOfStringConst.fs + SOURCE=NameOfAppliedFunction.fs # NameOfAppliedFunction.fs + SOURCE=NameOfIntegerAppliedFunction.fs # NameOfIntegerAppliedFunction.fs + SOURCE=NameOfPartiallyAppliedFunction.fs # NameOfPartiallyAppliedFunction.fs \ No newline at end of file From c57cfdc15439ee6c57e626b4a9ddb4e8c01ed61a Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 17 Nov 2014 14:52:46 +0100 Subject: [PATCH 07/21] Add some tests for name lookup of operators --- .../FSharp.Core.Unittests/NameOfTests.fs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 8a78965097..896dda30d1 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -105,10 +105,37 @@ type BasicNameOfTests() = 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) \ No newline at end of file + Assert.AreEqual("MethodGroup",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) \ No newline at end of file From c0beb959e9a080a15fb2edbad7c17b8bbfa98144 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 17 Nov 2014 16:45:51 +0100 Subject: [PATCH 08/21] Don't allow to use nameof(1+2) --- src/fsharp/check.fs | 18 +++++++++--------- .../NameOf/NameOfAdditionExpr.fs | 7 +++++++ .../DataExpressions/NameOf/NameOfDictLookup.fs | 8 ++++++++ .../Expressions/DataExpressions/NameOf/env.lst | 4 +++- 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAdditionExpr.fs create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfDictLookup.fs diff --git a/src/fsharp/check.fs b/src/fsharp/check.fs index 48bb48b15b..39a9010916 100644 --- a/src/fsharp/check.fs +++ b/src/fsharp/check.fs @@ -430,18 +430,18 @@ let extractNameOf args = match args with | [expr] -> match expr with - | Expr.Val(r,_,_) -> Some r.CompiledName - | Expr.App(Expr.Val(r,_,_),_,_,[Expr.Const(constant,_,_)],_) -> + | 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 property getters - Some r.CompiledName + Some(r.CompiledName) else None // the function was applied - | Expr.App(Expr.Val(r,_,_),_,_,_,_) -> Some r.CompiledName - | 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 + | Expr.App(Expr.Val(r,_,_),_,_,_,_) -> Some(r.CompiledName) + | 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 diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAdditionExpr.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAdditionExpr.fs new file mode 100644 index 0000000000..0bd01cf99a --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/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/NameOfDictLookup.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfDictLookup.fs new file mode 100644 index 0000000000..d3c2b3f1b3 --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/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/env.lst b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst index 97b034ae0d..f8ea6f2773 100644 --- a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst @@ -2,4 +2,6 @@ SOURCE=NameOfStringConst.fs # NameOfStringConst.fs SOURCE=NameOfAppliedFunction.fs # NameOfAppliedFunction.fs SOURCE=NameOfIntegerAppliedFunction.fs # NameOfIntegerAppliedFunction.fs - SOURCE=NameOfPartiallyAppliedFunction.fs # NameOfPartiallyAppliedFunction.fs \ No newline at end of file + SOURCE=NameOfPartiallyAppliedFunction.fs # NameOfPartiallyAppliedFunction.fs + SOURCE=NameOfDictLookup.fs # NameOfDictLookup.fs + SOURCE=NameOfAdditionExpr.fs # NameOfAdditionExpr.fs \ No newline at end of file From 8a46d36f0eea94edfa56194e047a5841401a03ea Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 17 Nov 2014 18:15:14 +0100 Subject: [PATCH 09/21] Dogfood the nameof operator in FSharp.Core --- src/fsharp/FSharp.Core/Linq.fs | 2 +- src/fsharp/FSharp.Core/Query.fs | 6 +- src/fsharp/FSharp.Core/array.fs | 314 +++++++++++++-------------- src/fsharp/FSharp.Core/array2.fs | 16 +- src/fsharp/FSharp.Core/array3.fs | 8 +- src/fsharp/FSharp.Core/local.fs | 28 +-- src/fsharp/FSharp.Core/math/n.fs | 2 +- src/fsharp/FSharp.Core/math/z.fs | 24 +- src/fsharp/FSharp.Core/quotations.fs | 82 +++---- src/fsharp/FSharp.Core/reflect.fs | 110 +++++----- src/fsharp/FSharp.Core/seq.fs | 238 ++++++++++---------- src/fsharp/FlatList.fs | 12 +- 12 files changed, 421 insertions(+), 421 deletions(-) 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/local.fs b/src/fsharp/FSharp.Core/local.fs index db39d0b15d..08cc96b6af 100644 --- a/src/fsharp/FSharp.Core/local.fs +++ b/src/fsharp/FSharp.Core/local.fs @@ -119,7 +119,7 @@ module internal List = let cons2 = freshConsNoTail (f.Invoke(h1,h2)) setFreshConsTail cons cons2; map2ToFreshConsTail cons2 f t1 t2 - | _ -> invalidArg "xs2" (SR.GetString(SR.listsHadDifferentLengths)) + | _ -> invalidArg (nameof xs2) (SR.GetString(SR.listsHadDifferentLengths)) let map2 f xs1 xs2 = match xs1,xs2 with @@ -129,7 +129,7 @@ module internal List = let cons = freshConsNoTail (f.Invoke(h1,h2)) map2ToFreshConsTail cons f t1 t2 cons - | _ -> invalidArg "xs2" (SR.GetString(SR.listsHadDifferentLengths)) + | _ -> invalidArg (nameof xs2) (SR.GetString(SR.listsHadDifferentLengths)) let rec indexedToFreshConsTail cons xs i = match xs with @@ -327,7 +327,7 @@ module internal List = let init count f = - if count < 0 then invalidArg "count" InputMustBeNonNegativeString + if count < 0 then invalidArg (nameof count) InputMustBeNonNegativeString if count = 0 then [] else let res = freshConsNoTail (f 0) @@ -344,7 +344,7 @@ module internal List = takeFreshConsTail cons2 (n - 1) xs let take n l = - if n < 0 then invalidArg "count" InputMustBeNonNegativeString + if n < 0 then invalidArg (nameof n) InputMustBeNonNegativeString if n = 0 then [] else match l with | [] -> raise <| System.InvalidOperationException (SR.GetString(SR.notEnoughElements)) @@ -366,7 +366,7 @@ module internal List = splitAtFreshConsTail cons2 (index - 1) xs let splitAt index l = - if index < 0 then invalidArg "index" (SR.GetString(SR.inputMustBeNonNegative)) + if index < 0 then invalidArg (nameof index) (SR.GetString(SR.inputMustBeNonNegative)) if index = 0 then [], l else match l with | [] -> raise <| System.InvalidOperationException (SR.GetString(SR.notEnoughElements)) @@ -442,7 +442,7 @@ module internal List = truncateToFreshConsTail cons2 (count-1) t let truncate count list = - if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative)) + if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative)) match list with | [] -> list | _ :: ([] as nil) -> if count > 0 then list else nil @@ -539,7 +539,7 @@ module internal List = windowedToFreshConsTail cons2 windowSize i t arr let windowed windowSize list = - if windowSize <= 0 then invalidArg "windowSize" (SR.GetString(SR.inputMustBeNonNegative)) + if windowSize <= 0 then invalidArg (nameof windowSize) (SR.GetString(SR.inputMustBeNonNegative)) match list with | [] -> [] | _ -> @@ -569,7 +569,7 @@ module internal List = setFreshConsTail cons cons2; zipToFreshConsTail cons2 t1 t2 | _ -> - invalidArg "xs2" (SR.GetString(SR.listsHadDifferentLengths)) + invalidArg (nameof xs2) (SR.GetString(SR.listsHadDifferentLengths)) // optimized mutation-based implementation. This code is only valid in fslib, where mutation of private // tail cons cells is permitted in carefully written library code. @@ -581,7 +581,7 @@ module internal List = zipToFreshConsTail res t1 t2; res | _ -> - invalidArg "xs2" (SR.GetString(SR.listsHadDifferentLengths)) + invalidArg (nameof xs2) (SR.GetString(SR.listsHadDifferentLengths)) // optimized mutation-based implementation. This code is only valid in fslib, where mutation of private // tail cons cells is permitted in carefully written library code. @@ -594,7 +594,7 @@ module internal List = setFreshConsTail cons cons2; zip3ToFreshConsTail cons2 t1 t2 t3 | _ -> - invalidArg "xs1" (SR.GetString(SR.listsHadDifferentLengths)) + invalidArg (nameof xs1) (SR.GetString(SR.listsHadDifferentLengths)) // optimized mutation-based implementation. This code is only valid in fslib, where mutation of private // tail cons cells is permitted in carefully written library code. @@ -607,7 +607,7 @@ module internal List = zip3ToFreshConsTail res t1 t2 t3; res | _ -> - invalidArg "xs1" (SR.GetString(SR.listsHadDifferentLengths)) + invalidArg (nameof xs1) (SR.GetString(SR.listsHadDifferentLengths)) let rec takeWhileFreshConsTail cons p l = match l with @@ -714,7 +714,7 @@ module internal Array = (# "newarr !0" type ('T) count : 'T array #) let inline init (count:int) (f: int -> 'T) = - if count < 0 then invalidArg "count" InputMustBeNonNegativeString + if count < 0 then invalidArg (nameof count) InputMustBeNonNegativeString let arr = (zeroCreateUnchecked count : 'T array) for i = 0 to count - 1 do arr.[i] <- f i @@ -755,11 +755,11 @@ module internal Array = let inv = zeroCreateUnchecked arr.Length for i = 0 to arr.Length - 1 do let j = indexMap i - if j < 0 || j >= arr.Length then invalidArg "indexMap" (SR.GetString(SR.notAPermutation)) + if j < 0 || j >= arr.Length then invalidArg (nameof indexMap) (SR.GetString(SR.notAPermutation)) res.[j] <- arr.[i] inv.[j] <- 1uy for i = 0 to arr.Length - 1 do - if inv.[i] <> 1uy then invalidArg "indexMap" (SR.GetString(SR.notAPermutation)) + if inv.[i] <> 1uy then invalidArg (nameof indexMap) (SR.GetString(SR.notAPermutation)) res let mapFold f acc (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/quotations.fs b/src/fsharp/FSharp.Core/quotations.fs index 93240a7ad6..1af264dbfe 100644 --- a/src/fsharp/FSharp.Core/quotations.fs +++ b/src/fsharp/FSharp.Core/quotations.fs @@ -106,8 +106,8 @@ type Var(name: string, typ:Type, ?isMutable: bool) = member v.Stamp = stamp static member Global(name,typ: Type) = - checkNonNull "name" name - checkNonNull "typ" typ + checkNonNull (nameof name) name + checkNonNull (nameof typ) typ lock globals (fun () -> let mutable res = Unchecked.defaultof let ok = globals.TryGetValue((name,typ),&res) @@ -507,7 +507,7 @@ module Patterns = let getUnionCaseInfoField(unionCase:UnionCaseInfo,index) = let fields = unionCase.GetFields() - if index < 0 || index >= fields.Length then invalidArg "index" (SR.GetString(SR.QinvalidCaseIndex)) + if index < 0 || index >= fields.Length then invalidArg (nameof index) (SR.GetString(SR.QinvalidCaseIndex)) fields.[index] /// Returns type of lambda applciation - something like "(fun a -> ..) b" @@ -587,14 +587,14 @@ module Patterns = let checkTypesSR (expectedType: Type) (receivedType : Type) name (threeHoleSR : string) = if (expectedType <> receivedType) then - invalidArg "receivedType" (String.Format(threeHoleSR, name, expectedType, receivedType)) + invalidArg (nameof receivedType) (String.Format(threeHoleSR, name, expectedType, receivedType)) let checkTypesWeakSR (expectedType: Type) (receivedType : Type) name (threeHoleSR : string) = if (not (assignableFrom expectedType receivedType)) then - invalidArg "receivedType" (String.Format(threeHoleSR, name, expectedType, receivedType)) + invalidArg (nameof receivedType) (String.Format(threeHoleSR, name, expectedType, receivedType)) let checkArgs (paramInfos: ParameterInfo[]) (args:list) = - if (paramInfos.Length <> args.Length) then invalidArg "args" (SR.GetString(SR.QincorrectNumArgs)) + if (paramInfos.Length <> args.Length) then invalidArg (nameof args) (SR.GetString(SR.QincorrectNumArgs)) List.iter2 ( fun (p:ParameterInfo) a -> checkTypesWeakSR p.ParameterType (typeOf a) "args" (SR.GetString(SR.QtmmInvalidParam))) (paramInfos |> Array.toList) @@ -602,14 +602,14 @@ module Patterns = // todo: shouldn't this be "strong" type check? sometimes? let checkAssignableFrom ty1 ty2 = - if not (assignableFrom ty1 ty2) then invalidArg "ty2" (SR.GetString(SR.QincorrectType)) + if not (assignableFrom ty1 ty2) then invalidArg (nameof ty2) (SR.GetString(SR.QincorrectType)) let checkObj (membInfo: MemberInfo) (obj: Expr) = // The MemberInfo may be a property associated with a union // find the actual related union type let rec loop (ty:Type) = if FSharpType.IsUnion ty && FSharpType.IsUnion ty.BaseType then loop ty.BaseType else ty let declType = loop membInfo.DeclaringType - if not (assignableFrom declType (typeOf obj)) then invalidArg "obj" (SR.GetString(SR.QincorrectInstanceType)) + if not (assignableFrom declType (typeOf obj)) then invalidArg (nameof obj) (SR.GetString(SR.QincorrectInstanceType)) // Checks lambda application for correctnes @@ -900,7 +900,7 @@ module Patterns = | Some methInfo -> methInfo let bindMethodHelper (parentT: Type, nm,marity,argtys,rty) = - if parentT = null then invalidArg "parentT" (SR.GetString(SR.QparentCannotBeNull)) + if parentT = null then invalidArg (nameof parentT) (SR.GetString(SR.QparentCannotBeNull)) if marity = 0 then let tyargTs = if parentT.IsGenericType then parentT.GetGenericArguments() else [| |] let argTs = Array.ofList (List.map (instFormal tyargTs) argtys) @@ -1098,7 +1098,7 @@ module Patterns = #endif let chop n xs = - if n < 0 then invalidArg "n" (SR.GetString(SR.inputMustBeNonNegative)) + if n < 0 then invalidArg (nameof n) (SR.GetString(SR.inputMustBeNonNegative)) let rec split l = match l with | 0,xs -> [],xs @@ -1223,13 +1223,13 @@ module Patterns = let decodeFunTy args = match args with | [d;r] -> funTyC.MakeGenericType([| d; r |]) - | _ -> invalidArg "args" (SR.GetString(SR.QexpectedTwoTypes)) + | _ -> invalidArg (nameof args) (SR.GetString(SR.QexpectedTwoTypes)) let decodeArrayTy n (tys: Type list) = match tys with | [ty] -> if (n = 1) then ty.MakeArrayType() else ty.MakeArrayType(n) // typeof.MakeArrayType(1) returns "Int[*]" but we need "Int[]" - | _ -> invalidArg "tys" (SR.GetString(SR.QexpectedOneType)) + | _ -> invalidArg (nameof tys) (SR.GetString(SR.QexpectedOneType)) let mkNamedTycon (tcName,ass:Assembly) = match ass.GetType(tcName) with @@ -1237,7 +1237,7 @@ module Patterns = // For some reason we can get 'null' returned here even when a type with the right name exists... Hence search the slow way... match (ass.GetTypes() |> Array.tryFind (fun a -> a.FullName = tcName)) with | Some ty -> ty - | None -> invalidArg "tcName" (SR.GetString2(SR.QfailedToBindTypeInAssembly, tcName, ass.FullName)) // "Available types are:\n%A" tcName ass (ass.GetTypes() |> Array.map (fun a -> a.FullName)) + | None -> invalidArg (nameof tcName) (SR.GetString2(SR.QfailedToBindTypeInAssembly, tcName, ass.FullName)) // "Available types are:\n%A" tcName ass (ass.GetTypes() |> Array.map (fun a -> a.FullName)) | ty -> ty let decodeNamedTy tc tsR = mkNamedType(tc,tsR) @@ -1468,7 +1468,7 @@ module Patterns = if idx < 0 || idx >= l.Length then failwith "hole index out of range"; let h = l.[idx] match typeOf h with - | expected when expected <> ty -> invalidArg "receivedType" (String.Format(SR.GetString(SR.QtmmRaw), expected, ty)) + | expected when expected <> ty -> invalidArg (nameof t) (String.Format(SR.GetString(SR.QtmmRaw), expected, ty)) | _ -> h let rec freeInExprAcc bvs acc (E t) = @@ -1688,7 +1688,7 @@ module Patterns = decodedTopResources.Add((assem,rn),0) let resolveMethodBase (methodBase: MethodBase, tyargs: Type []) = - checkNonNull "methodBase" methodBase + checkNonNull (nameof methodBase) methodBase let data = let assem = methodBase.DeclaringType.Assembly let key = ReflectedDefinitionTableKey.GetKey methodBase @@ -1738,12 +1738,12 @@ module Patterns = | :? MethodInfo as minfo -> if minfo.IsGenericMethod then minfo.GetGenericArguments().Length else 0 | _ -> 0) if (expectedNumTypars <> tyargs.Length) then - invalidArg "tyargs" (SR.GetString3(SR.QwrongNumOfTypeArgs, methodBase.Name, expectedNumTypars.ToString(), tyargs.Length.ToString())); + invalidArg (nameof tyargs) (SR.GetString3(SR.QwrongNumOfTypeArgs, methodBase.Name, expectedNumTypars.ToString(), tyargs.Length.ToString())); Some(exprBuilder {typeInst = mkTyparSubst tyargs; vars=Map.empty; varn=0}) | None -> None let resolveMethodBaseInstantiated (methodBase:MethodBase) = - checkNonNull "methodBase" methodBase + checkNonNull (nameof methodBase) methodBase match methodBase with | :? MethodInfo as minfo -> let tyargs = @@ -1787,15 +1787,15 @@ type Expr with mkApplications (f, es) static member Call (methodInfo:MethodInfo, args) = - checkNonNull "methodInfo" methodInfo + checkNonNull (nameof methodInfo) methodInfo mkStaticMethodCall (methodInfo, args) static member Call (obj:Expr,methodInfo:MethodInfo, args) = - checkNonNull "methodInfo" methodInfo + checkNonNull (nameof methodInfo) methodInfo mkInstanceMethodCall (obj,methodInfo,args) static member Coerce (e:Expr, target:Type) = - checkNonNull "target" target + checkNonNull (nameof target) target mkCoerce (target, e) static member IfThenElse (g:Expr, t:Expr, e:Expr) = @@ -1807,19 +1807,19 @@ type Expr with //static member RangeStep: Expr * Expr * Expr -> Expr static member FieldGet (fieldInfo:FieldInfo) = - checkNonNull "fieldInfo" fieldInfo + checkNonNull (nameof fieldInfo) fieldInfo mkStaticFieldGet fieldInfo static member FieldGet (obj:Expr, fieldInfo:FieldInfo) = - checkNonNull "fieldInfo" fieldInfo + checkNonNull (nameof fieldInfo) fieldInfo mkInstanceFieldGet (obj, fieldInfo) static member FieldSet (fieldInfo:FieldInfo, v:Expr) = - checkNonNull "fieldInfo" fieldInfo + checkNonNull (nameof fieldInfo) fieldInfo mkStaticFieldSet (fieldInfo, v) static member FieldSet (obj:Expr, fieldInfo:FieldInfo, v:Expr) = - checkNonNull "fieldInfo" fieldInfo + checkNonNull (nameof fieldInfo) fieldInfo mkInstanceFieldSet (obj, fieldInfo, v) static member Lambda (v:Var, e:Expr) = mkLambda (v, e) @@ -1829,41 +1829,41 @@ type Expr with static member LetRecursive (binds, e:Expr) = mkLetRec (binds, e) static member NewObject (constructorInfo:ConstructorInfo, args) = - checkNonNull "constructorInfo" constructorInfo + checkNonNull (nameof constructorInfo) constructorInfo mkCtorCall (constructorInfo, args) static member DefaultValue (expressionType:Type) = - checkNonNull "expressionType" expressionType + checkNonNull (nameof expressionType) expressionType mkDefaultValue expressionType static member NewTuple es = mkNewTuple es static member NewRecord (recordType:Type, args) = - checkNonNull "recordType" recordType + checkNonNull (nameof recordType) recordType mkNewRecord (recordType, args) static member NewArray (elementType:Type, es) = - checkNonNull "elementType" elementType + checkNonNull (nameof elementType) elementType mkNewArray(elementType, es) static member NewDelegate (delegateType:Type, vs: Var list, body: Expr) = - checkNonNull "delegateType" delegateType + checkNonNull (nameof delegateType) delegateType mkNewDelegate(delegateType, mkIteratedLambdas (vs, body)) static member NewUnionCase (unionCase, es) = mkNewUnionCase (unionCase, es) static member PropertyGet (obj:Expr, property: PropertyInfo, ?args) = - checkNonNull "property" property + checkNonNull (nameof property) property mkInstancePropGet (obj, property, defaultArg args []) static member PropertyGet (property: PropertyInfo, ?args) = - checkNonNull "property" property + checkNonNull (nameof property) property mkStaticPropGet (property, defaultArg args []) static member PropertySet (obj:Expr, property:PropertyInfo, value:Expr, ?args) = - checkNonNull "property" property + checkNonNull (nameof property) property mkInstancePropSet(obj, property, defaultArg args [], value) static member PropertySet (property:PropertyInfo, value:Expr, ?args) = @@ -1884,7 +1884,7 @@ type Expr with mkTupleGet (typeOf e, n, e) static member TypeTest (e: Expr, target: Type) = - checkNonNull "target" target + checkNonNull (nameof target) target mkTypeTest (e, target) static member UnionCaseTest (e:Expr, unionCase: UnionCaseInfo) = @@ -1894,7 +1894,7 @@ type Expr with mkValue (box v, typeof<'T>) static member Value(obj: obj, expressionType: Type) = - checkNonNull "expressionType" expressionType + checkNonNull (nameof expressionType) expressionType mkValue(obj, expressionType) static member Var(v) = @@ -1908,22 +1908,22 @@ type Expr with //static member IsInlinedMethodInfo(minfo:MethodInfo) = false static member TryGetReflectedDefinition(methodBase:MethodBase) = - checkNonNull "methodBase" methodBase + checkNonNull (nameof methodBase) methodBase resolveMethodBaseInstantiated(methodBase) static member Cast(expr:Expr) = cast expr static member Deserialize(qualifyingType:Type, spliceTypes, spliceExprs, bytes: byte[]) = - checkNonNull "qualifyingType" qualifyingType - checkNonNull "bytes" bytes + checkNonNull (nameof qualifyingType) qualifyingType + checkNonNull (nameof bytes) bytes deserialize (qualifyingType, spliceTypes, spliceExprs, bytes) static member RegisterReflectedDefinitions(assembly:Assembly, nm, bytes) = - checkNonNull "assembly" assembly + checkNonNull (nameof assembly) assembly registerReflectedDefinitions(assembly, nm, bytes) static member GlobalVar<'T>(name) : Expr<'T> = - checkNonNull "name" name + checkNonNull (nameof name) name Expr.Var(Var.Global(name, typeof<'T>)) |> Expr.Cast [] @@ -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) @@ -2112,7 +2112,7 @@ module ExprShape = | VarTerm v -> ShapeVar(v) | LambdaTerm(v,b) -> ShapeLambda(v,b) | CombTerm(op,args) -> ShapeCombination(box (op,expr.CustomAttributes),args) - | HoleTerm _ -> invalidArg "expr" (SR.GetString(SR.QunexpectedHole)) + | HoleTerm _ -> invalidArg (nameof expr) (SR.GetString(SR.QunexpectedHole)) loop (e :> Expr) #endif diff --git a/src/fsharp/FSharp.Core/reflect.fs b/src/fsharp/FSharp.Core/reflect.fs index bb0a76051d..f93f3b68dc 100644 --- a/src/fsharp/FSharp.Core/reflect.fs +++ b/src/fsharp/FSharp.Core/reflect.fs @@ -445,8 +445,8 @@ module internal Impl = | _ -> caseTyp let getUnionTagConverter (typ:Type,bindingFlags) = - if isOptionType typ then (fun tag -> match tag with 0 -> "None" | 1 -> "Some" | _ -> invalidArg "tag" (SR.GetString(SR.outOfRange))) - elif isListType typ then (fun tag -> match tag with 0 -> "Empty" | 1 -> "Cons" | _ -> invalidArg "tag" (SR.GetString(SR.outOfRange))) + if isOptionType typ then (fun tag -> match tag with 0 -> "None" | 1 -> "Some" | _ -> invalidArg (nameof tag) (SR.GetString(SR.outOfRange))) + elif isListType typ then (fun tag -> match tag with 0 -> "Empty" | 1 -> "Cons" | _ -> invalidArg (nameof tag) (SR.GetString(SR.outOfRange))) else let tagfieldmap = getUnionTypeTagNameMap (typ,bindingFlags) |> Map.ofSeq (fun tag -> tagfieldmap.[tag]) @@ -556,12 +556,12 @@ module internal Impl = meth.Invoke(null,BindingFlags.Static ||| BindingFlags.InvokeMethod ||| bindingFlags,null,args,null)) #endif let checkUnionType(unionType,bindingFlags) = - checkNonNull "unionType" unionType; + checkNonNull (nameof unionType) unionType; if not (isUnionType (unionType,bindingFlags)) then if isUnionType (unionType,bindingFlags ||| BindingFlags.NonPublic) then - invalidArg "unionType" (SR.GetString1(SR.privateUnionType, unionType.FullName)) + invalidArg (nameof unionType) (SR.GetString1(SR.privateUnionType, unionType.FullName)) else - invalidArg "unionType" (SR.GetString1(SR.notAUnionType, unionType.FullName)) + invalidArg (nameof unionType) (SR.GetString1(SR.notAUnionType, unionType.FullName)) let emptyObjArray : obj[] = [| |] //----------------------------------------------------------------- @@ -613,11 +613,11 @@ module internal Impl = let tysB = tys.[maxTuple-1..] let tyB = mkTupleType tysB tuple8.MakeGenericType(Array.append tysA [| tyB |]) - | _ -> invalidArg "tys" (SR.GetString(SR.invalidTupleTypes)) + | _ -> invalidArg (nameof tys) (SR.GetString(SR.invalidTupleTypes)) let rec getTupleTypeInfo (typ:Type) = - if not (isTupleType (typ) ) then invalidArg "typ" (SR.GetString1(SR.notATupleType, typ.FullName)); + if not (isTupleType (typ) ) then invalidArg (nameof typ) (SR.GetString1(SR.notATupleType, typ.FullName)); let tyargs = typ.GetGenericArguments() if tyargs.Length = maxTuple then let tysA = tyargs.[0..tupleEncField-1] @@ -708,10 +708,10 @@ module internal Impl = maker1,Some(etys.[tupleEncField]) let getTupleReaderInfo (typ:Type,index:int) = - if index < 0 then invalidArg "index" (SR.GetString2(SR.tupleIndexOutOfRange, typ.FullName, index.ToString())) + if index < 0 then invalidArg (nameof index) (SR.GetString2(SR.tupleIndexOutOfRange, typ.FullName, index.ToString())) let props = typ.GetProperties(instancePropertyFlags ||| BindingFlags.Public) |> orderTupleProperties let get index = - if index >= props.Length then invalidArg "index" (SR.GetString2(SR.tupleIndexOutOfRange, typ.FullName, index.ToString())) + if index >= props.Length then invalidArg (nameof index) (SR.GetString2(SR.tupleIndexOutOfRange, typ.FullName, index.ToString())) props.[index] if index < tupleEncField then @@ -726,7 +726,7 @@ module internal Impl = let getFunctionTypeInfo (typ:Type) = - if not (isFunctionType typ) then invalidArg "typ" (SR.GetString1(SR.notAFunctionType, typ.FullName)) + if not (isFunctionType typ) then invalidArg (nameof typ) (SR.GetString1(SR.notAFunctionType, typ.FullName)) let tyargs = typ.GetGenericArguments() tyargs.[0], tyargs.[1] @@ -827,9 +827,9 @@ module internal Impl = let checkExnType (exceptionType, bindingFlags) = if not (isExceptionRepr (exceptionType,bindingFlags)) then if isExceptionRepr (exceptionType,bindingFlags ||| BindingFlags.NonPublic) then - invalidArg "exceptionType" (SR.GetString1(SR.privateExceptionType, exceptionType.FullName)) + invalidArg (nameof exceptionType) (SR.GetString1(SR.privateExceptionType, exceptionType.FullName)) else - invalidArg "exceptionType" (SR.GetString1(SR.notAnExceptionType, exceptionType.FullName)) + invalidArg (nameof exceptionType) (SR.GetString1(SR.notAnExceptionType, exceptionType.FullName)) let checkRecordType(argName,recordType,bindingFlags) = checkNonNull argName recordType; @@ -885,47 +885,47 @@ type UnionCaseInfo(typ: System.Type, tag:int) = type FSharpType = static member IsTuple(typ:Type) = - Impl.checkNonNull "typ" typ; + Impl.checkNonNull (nameof typ) typ; Impl.isTupleType typ static member IsRecord(typ:Type,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "typ" typ; + Impl.checkNonNull (nameof typ) typ; Impl.isRecordType (typ,bindingFlags) static member IsUnion(typ:Type,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "typ" typ; + Impl.checkNonNull (nameof typ) typ; let typ = Impl.getTypeOfReprType (typ ,BindingFlags.Public ||| BindingFlags.NonPublic) Impl.isUnionType (typ,bindingFlags) static member IsFunction(typ:Type) = - Impl.checkNonNull "typ" typ; + Impl.checkNonNull (nameof typ) typ; let typ = Impl.getTypeOfReprType (typ ,BindingFlags.Public ||| BindingFlags.NonPublic) Impl.isFunctionType typ static member IsModule(typ:Type) = - Impl.checkNonNull "typ" typ; + Impl.checkNonNull (nameof typ) typ; Impl.isModuleType typ static member MakeFunctionType(domain:Type,range:Type) = - Impl.checkNonNull "domain" domain; - Impl.checkNonNull "range" range; + Impl.checkNonNull (nameof domain) domain; + Impl.checkNonNull (nameof range) range; Impl.func.MakeGenericType [| domain; range |] static member MakeTupleType(types:Type[]) = - Impl.checkNonNull "types" types; + Impl.checkNonNull (nameof types) types; if types |> Array.exists (function null -> true | _ -> false) then - invalidArg "types" (SR.GetString(SR.nullsNotAllowedInArray)) + invalidArg (nameof types) (SR.GetString(SR.nullsNotAllowedInArray)) Impl.mkTupleType types static member GetTupleElements(tupleType:Type) = - Impl.checkTupleType("tupleType",tupleType); + Impl.checkTupleType(nameof tupleType,tupleType); Impl.getTupleTypeInfo tupleType static member GetFunctionElements(functionType:Type) = - Impl.checkNonNull "functionType" functionType; + Impl.checkNonNull (nameof functionType) functionType; let functionType = Impl.getTypeOfReprType (functionType ,BindingFlags.Public ||| BindingFlags.NonPublic) Impl.getFunctionTypeInfo functionType @@ -936,19 +936,19 @@ type FSharpType = static member GetUnionCases (unionType:Type,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "unionType" unionType; + Impl.checkNonNull (nameof unionType) unionType; let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags) Impl.checkUnionType(unionType,bindingFlags); Impl.getUnionTypeTagNameMap(unionType,bindingFlags) |> Array.mapi (fun i _ -> UnionCaseInfo(unionType,i)) static member IsExceptionRepresentation(exceptionType:Type, ?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "exceptionType" exceptionType; + Impl.checkNonNull (nameof exceptionType) exceptionType; Impl.isExceptionRepr(exceptionType,bindingFlags) static member GetExceptionFields(exceptionType:Type, ?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "exceptionType" exceptionType; + Impl.checkNonNull (nameof exceptionType) exceptionType; Impl.checkExnType(exceptionType,bindingFlags); Impl.fieldPropsOfRecordType (exceptionType,bindingFlags) @@ -966,21 +966,21 @@ type FSharpValue = Impl.getRecordConstructor (recordType,bindingFlags) args static member GetRecordField(record:obj,info:PropertyInfo) = - Impl.checkNonNull "info" info; - Impl.checkNonNull "record" record; + Impl.checkNonNull (nameof info) info; + Impl.checkNonNull (nameof record) record; let reprty = record.GetType() - if not (Impl.isRecordType(reprty,BindingFlags.Public ||| BindingFlags.NonPublic)) then invalidArg "record" (SR.GetString(SR.objIsNotARecord)); + if not (Impl.isRecordType(reprty,BindingFlags.Public ||| BindingFlags.NonPublic)) then invalidArg (nameof record) (SR.GetString(SR.objIsNotARecord)); info.GetValue(record,null) static member GetRecordFields(record:obj,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "record" record; + Impl.checkNonNull (nameof record) record; let typ = record.GetType() - if not (Impl.isRecordType(typ,bindingFlags)) then invalidArg "record" (SR.GetString(SR.objIsNotARecord)); + if not (Impl.isRecordType(typ,bindingFlags)) then invalidArg (nameof record) (SR.GetString(SR.objIsNotARecord)); Impl.getRecordReader (typ,bindingFlags) record static member PreComputeRecordFieldReader(info:PropertyInfo) = - Impl.checkNonNull "info" info; + Impl.checkNonNull (nameof info) info; (fun (obj:obj) -> info.GetValue(obj,null)) static member PreComputeRecordReader(recordType:Type,?bindingFlags) : (obj -> obj[]) = @@ -999,9 +999,9 @@ type FSharpValue = Impl.getRecordConstructorMethod(recordType,bindingFlags) static member MakeFunction(functionType:Type,implementation:(obj->obj)) = - Impl.checkNonNull "functionType" functionType; - if not (Impl.isFunctionType functionType) then invalidArg "functionType" (SR.GetString1(SR.notAFunctionType, functionType.FullName)); - Impl.checkNonNull "implementation" implementation; + Impl.checkNonNull (nameof functionType) functionType; + if not (Impl.isFunctionType functionType) then invalidArg (nameof functionType) (SR.GetString1(SR.notAFunctionType, functionType.FullName)); + Impl.checkNonNull (nameof implementation) implementation; let domain,range = Impl.getFunctionTypeInfo functionType let dynCloMakerTy = typedefof> let saverTy = dynCloMakerTy.MakeGenericType [| domain; range |] @@ -1010,53 +1010,53 @@ type FSharpValue = f implementation static member MakeTuple(tupleElements: obj[],tupleType:Type) = - Impl.checkNonNull "tupleElements" tupleElements; - Impl.checkTupleType("tupleType",tupleType) + Impl.checkNonNull (nameof tupleElements) tupleElements; + Impl.checkTupleType(nameof tupleType,tupleType) Impl.getTupleConstructor tupleType tupleElements static member GetTupleFields(tuple:obj) = // argument name(s) used in error message - Impl.checkNonNull "tuple" tuple; + Impl.checkNonNull (nameof tuple) tuple; let typ = tuple.GetType() - if not (Impl.isTupleType typ ) then invalidArg "tuple" (SR.GetString1(SR.notATupleType, tuple.GetType().FullName)); + if not (Impl.isTupleType typ ) then invalidArg (nameof tuple) (SR.GetString1(SR.notATupleType, tuple.GetType().FullName)); Impl.getTupleReader typ tuple static member GetTupleField(tuple:obj,index:int) = // argument name(s) used in error message - Impl.checkNonNull "tuple" tuple; + Impl.checkNonNull (nameof tuple) tuple; let typ = tuple.GetType() - if not (Impl.isTupleType typ ) then invalidArg "tuple" (SR.GetString1(SR.notATupleType, tuple.GetType().FullName)); + if not (Impl.isTupleType typ ) then invalidArg (nameof tuple) (SR.GetString1(SR.notATupleType, tuple.GetType().FullName)); let fields = Impl.getTupleReader typ tuple - if index < 0 || index >= fields.Length then invalidArg "index" (SR.GetString2(SR.tupleIndexOutOfRange, tuple.GetType().FullName, index.ToString())); + if index < 0 || index >= fields.Length then invalidArg (nameof index) (SR.GetString2(SR.tupleIndexOutOfRange, tuple.GetType().FullName, index.ToString())); fields.[index] static member PreComputeTupleReader(tupleType:Type) : (obj -> obj[]) = - Impl.checkTupleType("tupleType",tupleType) + Impl.checkTupleType(nameof tupleType,tupleType) Impl.getTupleReader tupleType static member PreComputeTuplePropertyInfo(tupleType:Type,index:int) = - Impl.checkTupleType("tupleType",tupleType) + Impl.checkTupleType(nameof tupleType,tupleType) Impl.getTupleReaderInfo (tupleType,index) static member PreComputeTupleConstructor(tupleType:Type) = - Impl.checkTupleType("tupleType",tupleType) + Impl.checkTupleType(nameof tupleType,tupleType) Impl.getTupleConstructor tupleType static member PreComputeTupleConstructorInfo(tupleType:Type) = - Impl.checkTupleType("tupleType",tupleType) + Impl.checkTupleType(nameof tupleType,tupleType) Impl.getTupleConstructorInfo (tupleType) static member MakeUnion(unionCase:UnionCaseInfo,args: obj [],?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "unionCase" unionCase; + Impl.checkNonNull (nameof unionCase) unionCase; Impl.getUnionCaseConstructor (unionCase.DeclaringType,unionCase.Tag,bindingFlags) args static member PreComputeUnionConstructor (unionCase:UnionCaseInfo,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "unionCase" unionCase; + Impl.checkNonNull (nameof unionCase) unionCase; Impl.getUnionCaseConstructor (unionCase.DeclaringType,unionCase.Tag,bindingFlags) static member PreComputeUnionConstructorInfo(unionCase:UnionCaseInfo, ?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "unionCase" unionCase; + Impl.checkNonNull (nameof unionCase) unionCase; Impl.getUnionCaseConstructorMethod (unionCase.DeclaringType,unionCase.Tag,bindingFlags) static member GetUnionFields(obj:obj,unionType:Type,?bindingFlags) = @@ -1065,13 +1065,13 @@ type FSharpValue = match typ with | null -> match obj with - | null -> invalidArg "obj" (SR.GetString(SR.objIsNullAndNoType)) + | null -> invalidArg (nameof obj) (SR.GetString(SR.objIsNullAndNoType)) | _ -> obj.GetType() | _ -> typ //System.Console.WriteLine("typ1 = {0}",box unionType) let unionType = ensureType(unionType,obj) //System.Console.WriteLine("typ2 = {0}",box unionType) - Impl.checkNonNull "unionType" unionType; + Impl.checkNonNull (nameof unionType) unionType; let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags) //System.Console.WriteLine("typ3 = {0}",box unionType) Impl.checkUnionType(unionType,bindingFlags); @@ -1081,7 +1081,7 @@ type FSharpValue = static member PreComputeUnionTagReader(unionType: Type,?bindingFlags) : (obj -> int) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "unionType" unionType; + Impl.checkNonNull (nameof unionType) unionType; let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags) Impl.checkUnionType(unionType,bindingFlags); Impl.getUnionTagReader (unionType ,bindingFlags) @@ -1089,20 +1089,20 @@ type FSharpValue = static member PreComputeUnionTagMemberInfo(unionType: Type,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "unionType" unionType; + Impl.checkNonNull (nameof unionType) unionType; let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags) Impl.checkUnionType(unionType,bindingFlags); Impl.getUnionTagMemberInfo(unionType ,bindingFlags) static member PreComputeUnionReader(unionCase: UnionCaseInfo,?bindingFlags) : (obj -> obj[]) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "unionCase" unionCase; + Impl.checkNonNull (nameof unionCase) unionCase; let typ = unionCase.DeclaringType Impl.getUnionCaseRecordReader (typ,unionCase.Tag,bindingFlags) static member GetExceptionFields(exn:obj, ?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull "exn" exn; + Impl.checkNonNull (nameof exn) exn; let typ = exn.GetType() Impl.checkExnType(typ,bindingFlags); Impl.getRecordReader (typ,bindingFlags) exn 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/FlatList.fs b/src/fsharp/FlatList.fs index 9d38eedea2..3ed1c749de 100644 --- a/src/fsharp/FlatList.fs +++ b/src/fsharp/FlatList.fs @@ -60,7 +60,7 @@ module internal FlatList = let fold2 f acc (x:FlatList<_>) (y:FlatList<_>) = match x.array,y.array with | null,null -> acc - | null,_ | _,null -> invalidArg "x" "mismatched list lengths" + | null,_ | _,null -> invalidArg (nameof x) "mismatched list lengths" | arr1,arr2 -> Array.fold2 f acc arr1 arr2 let foldBack f (x:FlatList<_>) acc = @@ -71,13 +71,13 @@ module internal FlatList = let foldBack2 f (x:FlatList<_>) (y:FlatList<_>) acc = match x.array,y.array with | null,null -> acc - | null,_ | _,null -> invalidArg "x" "mismatched list lengths" + | null,_ | _,null -> invalidArg (nameof x) "mismatched list lengths" | arr1,arr2 -> Array.foldBack2 f arr1 arr2 acc let map2 f (x:FlatList<_>) (y:FlatList<_>) = match x.array,y.array with | null,null -> FlatList.Empty - | null,_ | _,null -> invalidArg "x" "mismatched list lengths" + | null,_ | _,null -> invalidArg (nameof x) "mismatched list lengths" | arr1,arr2 -> FlatList(Array.map2 f arr1 arr2) let forall f (x:FlatList<_>) = @@ -88,13 +88,13 @@ module internal FlatList = let forall2 f (x1:FlatList<_>) (x2:FlatList<_>) = match x1.array, x2.array with | null,null -> true - | null,_ | _,null -> invalidArg "x1" "mismatched list lengths" + | null,_ | _,null -> invalidArg (nameof x1) "mismatched list lengths" | arr1,arr2 -> Array.forall2 f arr1 arr2 let iter2 f (x1:FlatList<_>) (x2:FlatList<_>) = match x1.array, x2.array with | null,null -> () - | null,_ | _,null -> invalidArg "x1" "mismatched list lengths" + | null,_ | _,null -> invalidArg (nameof x1) "mismatched list lengths" | arr1,arr2 -> Array.iter2 f arr1 arr2 let partition f (x:FlatList<_>) = @@ -186,7 +186,7 @@ module internal FlatList = let zip (x:FlatList<_>) (y:FlatList<_>) = match x.array,y.array with | null,null -> FlatList.Empty - | null,_ | _,null -> invalidArg "x" "mismatched list lengths" + | null,_ | _,null -> invalidArg (nameof x) "mismatched list lengths" | arr1,arr2 -> FlatList(Array.zip arr1 arr2) #endif From 9663c8f5b3c1caf24f81f23ac6ef011f1f5ae6fb Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 09:22:48 +0100 Subject: [PATCH 10/21] NameOf should not work on applied functions --- src/fsharp/check.fs | 9 +++++++-- .../NameOf/NameOfParameterAppliedFunction.fs | 9 +++++++++ .../Expressions/DataExpressions/NameOf/env.lst | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfParameterAppliedFunction.fs diff --git a/src/fsharp/check.fs b/src/fsharp/check.fs index 39a9010916..1dc53ce5ca 100644 --- a/src/fsharp/check.fs +++ b/src/fsharp/check.fs @@ -432,11 +432,16 @@ let extractNameOf args = 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 property getters + if r.CompiledName.StartsWith("get_") && constant = Const.Unit then // TODO: We need a better way to find static property getters + Some(r.CompiledName) + 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) else None // the function was applied - | Expr.App(Expr.Val(r,_,_),_,_,_,_) -> Some(r.CompiledName) | 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) diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfParameterAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfParameterAppliedFunction.fs new file mode 100644 index 0000000000..489d0af27d --- /dev/null +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/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/env.lst b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst index f8ea6f2773..33c0ef0344 100644 --- a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst @@ -4,4 +4,5 @@ SOURCE=NameOfIntegerAppliedFunction.fs # NameOfIntegerAppliedFunction.fs SOURCE=NameOfPartiallyAppliedFunction.fs # NameOfPartiallyAppliedFunction.fs SOURCE=NameOfDictLookup.fs # NameOfDictLookup.fs - SOURCE=NameOfAdditionExpr.fs # NameOfAdditionExpr.fs \ No newline at end of file + SOURCE=NameOfAdditionExpr.fs # NameOfAdditionExpr.fs + SOURCE=NameOfParameterAppliedFunction.fs # NameOfParameterAppliedFunction.fs \ No newline at end of file From 427f8888973d07216bc0a2f9f6202316e279df35 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 14:13:15 +0100 Subject: [PATCH 11/21] Revert problematic FSharp.Core files --- src/fsharp/FSharp.Core/local.fs | 28 +++---- src/fsharp/FSharp.Core/quotations.fs | 80 +++++++++---------- src/fsharp/FSharp.Core/reflect.fs | 110 +++++++++++++-------------- src/fsharp/FlatList.fs | 12 +-- 4 files changed, 115 insertions(+), 115 deletions(-) diff --git a/src/fsharp/FSharp.Core/local.fs b/src/fsharp/FSharp.Core/local.fs index 08cc96b6af..db39d0b15d 100644 --- a/src/fsharp/FSharp.Core/local.fs +++ b/src/fsharp/FSharp.Core/local.fs @@ -119,7 +119,7 @@ module internal List = let cons2 = freshConsNoTail (f.Invoke(h1,h2)) setFreshConsTail cons cons2; map2ToFreshConsTail cons2 f t1 t2 - | _ -> invalidArg (nameof xs2) (SR.GetString(SR.listsHadDifferentLengths)) + | _ -> invalidArg "xs2" (SR.GetString(SR.listsHadDifferentLengths)) let map2 f xs1 xs2 = match xs1,xs2 with @@ -129,7 +129,7 @@ module internal List = let cons = freshConsNoTail (f.Invoke(h1,h2)) map2ToFreshConsTail cons f t1 t2 cons - | _ -> invalidArg (nameof xs2) (SR.GetString(SR.listsHadDifferentLengths)) + | _ -> invalidArg "xs2" (SR.GetString(SR.listsHadDifferentLengths)) let rec indexedToFreshConsTail cons xs i = match xs with @@ -327,7 +327,7 @@ module internal List = let init count f = - if count < 0 then invalidArg (nameof count) InputMustBeNonNegativeString + if count < 0 then invalidArg "count" InputMustBeNonNegativeString if count = 0 then [] else let res = freshConsNoTail (f 0) @@ -344,7 +344,7 @@ module internal List = takeFreshConsTail cons2 (n - 1) xs let take n l = - if n < 0 then invalidArg (nameof n) InputMustBeNonNegativeString + if n < 0 then invalidArg "count" InputMustBeNonNegativeString if n = 0 then [] else match l with | [] -> raise <| System.InvalidOperationException (SR.GetString(SR.notEnoughElements)) @@ -366,7 +366,7 @@ module internal List = splitAtFreshConsTail cons2 (index - 1) xs let splitAt index l = - if index < 0 then invalidArg (nameof index) (SR.GetString(SR.inputMustBeNonNegative)) + if index < 0 then invalidArg "index" (SR.GetString(SR.inputMustBeNonNegative)) if index = 0 then [], l else match l with | [] -> raise <| System.InvalidOperationException (SR.GetString(SR.notEnoughElements)) @@ -442,7 +442,7 @@ module internal List = truncateToFreshConsTail cons2 (count-1) t let truncate count list = - if count < 0 then invalidArg (nameof count) (SR.GetString(SR.inputMustBeNonNegative)) + if count < 0 then invalidArg "count" (SR.GetString(SR.inputMustBeNonNegative)) match list with | [] -> list | _ :: ([] as nil) -> if count > 0 then list else nil @@ -539,7 +539,7 @@ module internal List = windowedToFreshConsTail cons2 windowSize i t arr let windowed windowSize list = - if windowSize <= 0 then invalidArg (nameof windowSize) (SR.GetString(SR.inputMustBeNonNegative)) + if windowSize <= 0 then invalidArg "windowSize" (SR.GetString(SR.inputMustBeNonNegative)) match list with | [] -> [] | _ -> @@ -569,7 +569,7 @@ module internal List = setFreshConsTail cons cons2; zipToFreshConsTail cons2 t1 t2 | _ -> - invalidArg (nameof xs2) (SR.GetString(SR.listsHadDifferentLengths)) + invalidArg "xs2" (SR.GetString(SR.listsHadDifferentLengths)) // optimized mutation-based implementation. This code is only valid in fslib, where mutation of private // tail cons cells is permitted in carefully written library code. @@ -581,7 +581,7 @@ module internal List = zipToFreshConsTail res t1 t2; res | _ -> - invalidArg (nameof xs2) (SR.GetString(SR.listsHadDifferentLengths)) + invalidArg "xs2" (SR.GetString(SR.listsHadDifferentLengths)) // optimized mutation-based implementation. This code is only valid in fslib, where mutation of private // tail cons cells is permitted in carefully written library code. @@ -594,7 +594,7 @@ module internal List = setFreshConsTail cons cons2; zip3ToFreshConsTail cons2 t1 t2 t3 | _ -> - invalidArg (nameof xs1) (SR.GetString(SR.listsHadDifferentLengths)) + invalidArg "xs1" (SR.GetString(SR.listsHadDifferentLengths)) // optimized mutation-based implementation. This code is only valid in fslib, where mutation of private // tail cons cells is permitted in carefully written library code. @@ -607,7 +607,7 @@ module internal List = zip3ToFreshConsTail res t1 t2 t3; res | _ -> - invalidArg (nameof xs1) (SR.GetString(SR.listsHadDifferentLengths)) + invalidArg "xs1" (SR.GetString(SR.listsHadDifferentLengths)) let rec takeWhileFreshConsTail cons p l = match l with @@ -714,7 +714,7 @@ module internal Array = (# "newarr !0" type ('T) count : 'T array #) let inline init (count:int) (f: int -> 'T) = - if count < 0 then invalidArg (nameof count) InputMustBeNonNegativeString + if count < 0 then invalidArg "count" InputMustBeNonNegativeString let arr = (zeroCreateUnchecked count : 'T array) for i = 0 to count - 1 do arr.[i] <- f i @@ -755,11 +755,11 @@ module internal Array = let inv = zeroCreateUnchecked arr.Length for i = 0 to arr.Length - 1 do let j = indexMap i - if j < 0 || j >= arr.Length then invalidArg (nameof indexMap) (SR.GetString(SR.notAPermutation)) + if j < 0 || j >= arr.Length then invalidArg "indexMap" (SR.GetString(SR.notAPermutation)) res.[j] <- arr.[i] inv.[j] <- 1uy for i = 0 to arr.Length - 1 do - if inv.[i] <> 1uy then invalidArg (nameof indexMap) (SR.GetString(SR.notAPermutation)) + if inv.[i] <> 1uy then invalidArg "indexMap" (SR.GetString(SR.notAPermutation)) res let mapFold f acc (array : _[]) = diff --git a/src/fsharp/FSharp.Core/quotations.fs b/src/fsharp/FSharp.Core/quotations.fs index 1af264dbfe..255ef3a829 100644 --- a/src/fsharp/FSharp.Core/quotations.fs +++ b/src/fsharp/FSharp.Core/quotations.fs @@ -106,8 +106,8 @@ type Var(name: string, typ:Type, ?isMutable: bool) = member v.Stamp = stamp static member Global(name,typ: Type) = - checkNonNull (nameof name) name - checkNonNull (nameof typ) typ + checkNonNull "name" name + checkNonNull "typ" typ lock globals (fun () -> let mutable res = Unchecked.defaultof let ok = globals.TryGetValue((name,typ),&res) @@ -507,7 +507,7 @@ module Patterns = let getUnionCaseInfoField(unionCase:UnionCaseInfo,index) = let fields = unionCase.GetFields() - if index < 0 || index >= fields.Length then invalidArg (nameof index) (SR.GetString(SR.QinvalidCaseIndex)) + if index < 0 || index >= fields.Length then invalidArg "index" (SR.GetString(SR.QinvalidCaseIndex)) fields.[index] /// Returns type of lambda applciation - something like "(fun a -> ..) b" @@ -587,14 +587,14 @@ module Patterns = let checkTypesSR (expectedType: Type) (receivedType : Type) name (threeHoleSR : string) = if (expectedType <> receivedType) then - invalidArg (nameof receivedType) (String.Format(threeHoleSR, name, expectedType, receivedType)) + invalidArg "receivedType" (String.Format(threeHoleSR, name, expectedType, receivedType)) let checkTypesWeakSR (expectedType: Type) (receivedType : Type) name (threeHoleSR : string) = if (not (assignableFrom expectedType receivedType)) then - invalidArg (nameof receivedType) (String.Format(threeHoleSR, name, expectedType, receivedType)) + invalidArg "receivedType" (String.Format(threeHoleSR, name, expectedType, receivedType)) let checkArgs (paramInfos: ParameterInfo[]) (args:list) = - if (paramInfos.Length <> args.Length) then invalidArg (nameof args) (SR.GetString(SR.QincorrectNumArgs)) + if (paramInfos.Length <> args.Length) then invalidArg "args" (SR.GetString(SR.QincorrectNumArgs)) List.iter2 ( fun (p:ParameterInfo) a -> checkTypesWeakSR p.ParameterType (typeOf a) "args" (SR.GetString(SR.QtmmInvalidParam))) (paramInfos |> Array.toList) @@ -602,14 +602,14 @@ module Patterns = // todo: shouldn't this be "strong" type check? sometimes? let checkAssignableFrom ty1 ty2 = - if not (assignableFrom ty1 ty2) then invalidArg (nameof ty2) (SR.GetString(SR.QincorrectType)) + if not (assignableFrom ty1 ty2) then invalidArg "ty2" (SR.GetString(SR.QincorrectType)) let checkObj (membInfo: MemberInfo) (obj: Expr) = // The MemberInfo may be a property associated with a union // find the actual related union type let rec loop (ty:Type) = if FSharpType.IsUnion ty && FSharpType.IsUnion ty.BaseType then loop ty.BaseType else ty let declType = loop membInfo.DeclaringType - if not (assignableFrom declType (typeOf obj)) then invalidArg (nameof obj) (SR.GetString(SR.QincorrectInstanceType)) + if not (assignableFrom declType (typeOf obj)) then invalidArg "obj" (SR.GetString(SR.QincorrectInstanceType)) // Checks lambda application for correctnes @@ -900,7 +900,7 @@ module Patterns = | Some methInfo -> methInfo let bindMethodHelper (parentT: Type, nm,marity,argtys,rty) = - if parentT = null then invalidArg (nameof parentT) (SR.GetString(SR.QparentCannotBeNull)) + if parentT = null then invalidArg "parentT" (SR.GetString(SR.QparentCannotBeNull)) if marity = 0 then let tyargTs = if parentT.IsGenericType then parentT.GetGenericArguments() else [| |] let argTs = Array.ofList (List.map (instFormal tyargTs) argtys) @@ -1098,7 +1098,7 @@ module Patterns = #endif let chop n xs = - if n < 0 then invalidArg (nameof n) (SR.GetString(SR.inputMustBeNonNegative)) + if n < 0 then invalidArg "n" (SR.GetString(SR.inputMustBeNonNegative)) let rec split l = match l with | 0,xs -> [],xs @@ -1223,13 +1223,13 @@ module Patterns = let decodeFunTy args = match args with | [d;r] -> funTyC.MakeGenericType([| d; r |]) - | _ -> invalidArg (nameof args) (SR.GetString(SR.QexpectedTwoTypes)) + | _ -> invalidArg "args" (SR.GetString(SR.QexpectedTwoTypes)) let decodeArrayTy n (tys: Type list) = match tys with | [ty] -> if (n = 1) then ty.MakeArrayType() else ty.MakeArrayType(n) // typeof.MakeArrayType(1) returns "Int[*]" but we need "Int[]" - | _ -> invalidArg (nameof tys) (SR.GetString(SR.QexpectedOneType)) + | _ -> invalidArg "tys" (SR.GetString(SR.QexpectedOneType)) let mkNamedTycon (tcName,ass:Assembly) = match ass.GetType(tcName) with @@ -1237,7 +1237,7 @@ module Patterns = // For some reason we can get 'null' returned here even when a type with the right name exists... Hence search the slow way... match (ass.GetTypes() |> Array.tryFind (fun a -> a.FullName = tcName)) with | Some ty -> ty - | None -> invalidArg (nameof tcName) (SR.GetString2(SR.QfailedToBindTypeInAssembly, tcName, ass.FullName)) // "Available types are:\n%A" tcName ass (ass.GetTypes() |> Array.map (fun a -> a.FullName)) + | None -> invalidArg "tcName" (SR.GetString2(SR.QfailedToBindTypeInAssembly, tcName, ass.FullName)) // "Available types are:\n%A" tcName ass (ass.GetTypes() |> Array.map (fun a -> a.FullName)) | ty -> ty let decodeNamedTy tc tsR = mkNamedType(tc,tsR) @@ -1468,7 +1468,7 @@ module Patterns = if idx < 0 || idx >= l.Length then failwith "hole index out of range"; let h = l.[idx] match typeOf h with - | expected when expected <> ty -> invalidArg (nameof t) (String.Format(SR.GetString(SR.QtmmRaw), expected, ty)) + | expected when expected <> ty -> invalidArg "receivedType" (String.Format(SR.GetString(SR.QtmmRaw), expected, ty)) | _ -> h let rec freeInExprAcc bvs acc (E t) = @@ -1688,7 +1688,7 @@ module Patterns = decodedTopResources.Add((assem,rn),0) let resolveMethodBase (methodBase: MethodBase, tyargs: Type []) = - checkNonNull (nameof methodBase) methodBase + checkNonNull "methodBase" methodBase let data = let assem = methodBase.DeclaringType.Assembly let key = ReflectedDefinitionTableKey.GetKey methodBase @@ -1738,12 +1738,12 @@ module Patterns = | :? MethodInfo as minfo -> if minfo.IsGenericMethod then minfo.GetGenericArguments().Length else 0 | _ -> 0) if (expectedNumTypars <> tyargs.Length) then - invalidArg (nameof tyargs) (SR.GetString3(SR.QwrongNumOfTypeArgs, methodBase.Name, expectedNumTypars.ToString(), tyargs.Length.ToString())); + invalidArg "tyargs" (SR.GetString3(SR.QwrongNumOfTypeArgs, methodBase.Name, expectedNumTypars.ToString(), tyargs.Length.ToString())); Some(exprBuilder {typeInst = mkTyparSubst tyargs; vars=Map.empty; varn=0}) | None -> None let resolveMethodBaseInstantiated (methodBase:MethodBase) = - checkNonNull (nameof methodBase) methodBase + checkNonNull "methodBase" methodBase match methodBase with | :? MethodInfo as minfo -> let tyargs = @@ -1787,15 +1787,15 @@ type Expr with mkApplications (f, es) static member Call (methodInfo:MethodInfo, args) = - checkNonNull (nameof methodInfo) methodInfo + checkNonNull "methodInfo" methodInfo mkStaticMethodCall (methodInfo, args) static member Call (obj:Expr,methodInfo:MethodInfo, args) = - checkNonNull (nameof methodInfo) methodInfo + checkNonNull "methodInfo" methodInfo mkInstanceMethodCall (obj,methodInfo,args) static member Coerce (e:Expr, target:Type) = - checkNonNull (nameof target) target + checkNonNull "target" target mkCoerce (target, e) static member IfThenElse (g:Expr, t:Expr, e:Expr) = @@ -1807,19 +1807,19 @@ type Expr with //static member RangeStep: Expr * Expr * Expr -> Expr static member FieldGet (fieldInfo:FieldInfo) = - checkNonNull (nameof fieldInfo) fieldInfo + checkNonNull "fieldInfo" fieldInfo mkStaticFieldGet fieldInfo static member FieldGet (obj:Expr, fieldInfo:FieldInfo) = - checkNonNull (nameof fieldInfo) fieldInfo + checkNonNull "fieldInfo" fieldInfo mkInstanceFieldGet (obj, fieldInfo) static member FieldSet (fieldInfo:FieldInfo, v:Expr) = - checkNonNull (nameof fieldInfo) fieldInfo + checkNonNull "fieldInfo" fieldInfo mkStaticFieldSet (fieldInfo, v) static member FieldSet (obj:Expr, fieldInfo:FieldInfo, v:Expr) = - checkNonNull (nameof fieldInfo) fieldInfo + checkNonNull "fieldInfo" fieldInfo mkInstanceFieldSet (obj, fieldInfo, v) static member Lambda (v:Var, e:Expr) = mkLambda (v, e) @@ -1829,41 +1829,41 @@ type Expr with static member LetRecursive (binds, e:Expr) = mkLetRec (binds, e) static member NewObject (constructorInfo:ConstructorInfo, args) = - checkNonNull (nameof constructorInfo) constructorInfo + checkNonNull "constructorInfo" constructorInfo mkCtorCall (constructorInfo, args) static member DefaultValue (expressionType:Type) = - checkNonNull (nameof expressionType) expressionType + checkNonNull "expressionType" expressionType mkDefaultValue expressionType static member NewTuple es = mkNewTuple es static member NewRecord (recordType:Type, args) = - checkNonNull (nameof recordType) recordType + checkNonNull "recordType" recordType mkNewRecord (recordType, args) static member NewArray (elementType:Type, es) = - checkNonNull (nameof elementType) elementType + checkNonNull "elementType" elementType mkNewArray(elementType, es) static member NewDelegate (delegateType:Type, vs: Var list, body: Expr) = - checkNonNull (nameof delegateType) delegateType + checkNonNull "delegateType" delegateType mkNewDelegate(delegateType, mkIteratedLambdas (vs, body)) static member NewUnionCase (unionCase, es) = mkNewUnionCase (unionCase, es) static member PropertyGet (obj:Expr, property: PropertyInfo, ?args) = - checkNonNull (nameof property) property + checkNonNull "property" property mkInstancePropGet (obj, property, defaultArg args []) static member PropertyGet (property: PropertyInfo, ?args) = - checkNonNull (nameof property) property + checkNonNull "property" property mkStaticPropGet (property, defaultArg args []) static member PropertySet (obj:Expr, property:PropertyInfo, value:Expr, ?args) = - checkNonNull (nameof property) property + checkNonNull "property" property mkInstancePropSet(obj, property, defaultArg args [], value) static member PropertySet (property:PropertyInfo, value:Expr, ?args) = @@ -1884,7 +1884,7 @@ type Expr with mkTupleGet (typeOf e, n, e) static member TypeTest (e: Expr, target: Type) = - checkNonNull (nameof target) target + checkNonNull "target" target mkTypeTest (e, target) static member UnionCaseTest (e:Expr, unionCase: UnionCaseInfo) = @@ -1894,7 +1894,7 @@ type Expr with mkValue (box v, typeof<'T>) static member Value(obj: obj, expressionType: Type) = - checkNonNull (nameof expressionType) expressionType + checkNonNull "expressionType" expressionType mkValue(obj, expressionType) static member Var(v) = @@ -1908,22 +1908,22 @@ type Expr with //static member IsInlinedMethodInfo(minfo:MethodInfo) = false static member TryGetReflectedDefinition(methodBase:MethodBase) = - checkNonNull (nameof methodBase) methodBase + checkNonNull "methodBase" methodBase resolveMethodBaseInstantiated(methodBase) static member Cast(expr:Expr) = cast expr static member Deserialize(qualifyingType:Type, spliceTypes, spliceExprs, bytes: byte[]) = - checkNonNull (nameof qualifyingType) qualifyingType - checkNonNull (nameof bytes) bytes + checkNonNull "qualifyingType" qualifyingType + checkNonNull "bytes" bytes deserialize (qualifyingType, spliceTypes, spliceExprs, bytes) static member RegisterReflectedDefinitions(assembly:Assembly, nm, bytes) = - checkNonNull (nameof assembly) assembly + checkNonNull "assembly" assembly registerReflectedDefinitions(assembly, nm, bytes) static member GlobalVar<'T>(name) : Expr<'T> = - checkNonNull (nameof name) name + checkNonNull "name" name Expr.Var(Var.Global(name, typeof<'T>)) |> Expr.Cast [] @@ -2112,7 +2112,7 @@ module ExprShape = | VarTerm v -> ShapeVar(v) | LambdaTerm(v,b) -> ShapeLambda(v,b) | CombTerm(op,args) -> ShapeCombination(box (op,expr.CustomAttributes),args) - | HoleTerm _ -> invalidArg (nameof expr) (SR.GetString(SR.QunexpectedHole)) + | HoleTerm _ -> invalidArg "expr" (SR.GetString(SR.QunexpectedHole)) loop (e :> Expr) #endif diff --git a/src/fsharp/FSharp.Core/reflect.fs b/src/fsharp/FSharp.Core/reflect.fs index f93f3b68dc..bb0a76051d 100644 --- a/src/fsharp/FSharp.Core/reflect.fs +++ b/src/fsharp/FSharp.Core/reflect.fs @@ -445,8 +445,8 @@ module internal Impl = | _ -> caseTyp let getUnionTagConverter (typ:Type,bindingFlags) = - if isOptionType typ then (fun tag -> match tag with 0 -> "None" | 1 -> "Some" | _ -> invalidArg (nameof tag) (SR.GetString(SR.outOfRange))) - elif isListType typ then (fun tag -> match tag with 0 -> "Empty" | 1 -> "Cons" | _ -> invalidArg (nameof tag) (SR.GetString(SR.outOfRange))) + if isOptionType typ then (fun tag -> match tag with 0 -> "None" | 1 -> "Some" | _ -> invalidArg "tag" (SR.GetString(SR.outOfRange))) + elif isListType typ then (fun tag -> match tag with 0 -> "Empty" | 1 -> "Cons" | _ -> invalidArg "tag" (SR.GetString(SR.outOfRange))) else let tagfieldmap = getUnionTypeTagNameMap (typ,bindingFlags) |> Map.ofSeq (fun tag -> tagfieldmap.[tag]) @@ -556,12 +556,12 @@ module internal Impl = meth.Invoke(null,BindingFlags.Static ||| BindingFlags.InvokeMethod ||| bindingFlags,null,args,null)) #endif let checkUnionType(unionType,bindingFlags) = - checkNonNull (nameof unionType) unionType; + checkNonNull "unionType" unionType; if not (isUnionType (unionType,bindingFlags)) then if isUnionType (unionType,bindingFlags ||| BindingFlags.NonPublic) then - invalidArg (nameof unionType) (SR.GetString1(SR.privateUnionType, unionType.FullName)) + invalidArg "unionType" (SR.GetString1(SR.privateUnionType, unionType.FullName)) else - invalidArg (nameof unionType) (SR.GetString1(SR.notAUnionType, unionType.FullName)) + invalidArg "unionType" (SR.GetString1(SR.notAUnionType, unionType.FullName)) let emptyObjArray : obj[] = [| |] //----------------------------------------------------------------- @@ -613,11 +613,11 @@ module internal Impl = let tysB = tys.[maxTuple-1..] let tyB = mkTupleType tysB tuple8.MakeGenericType(Array.append tysA [| tyB |]) - | _ -> invalidArg (nameof tys) (SR.GetString(SR.invalidTupleTypes)) + | _ -> invalidArg "tys" (SR.GetString(SR.invalidTupleTypes)) let rec getTupleTypeInfo (typ:Type) = - if not (isTupleType (typ) ) then invalidArg (nameof typ) (SR.GetString1(SR.notATupleType, typ.FullName)); + if not (isTupleType (typ) ) then invalidArg "typ" (SR.GetString1(SR.notATupleType, typ.FullName)); let tyargs = typ.GetGenericArguments() if tyargs.Length = maxTuple then let tysA = tyargs.[0..tupleEncField-1] @@ -708,10 +708,10 @@ module internal Impl = maker1,Some(etys.[tupleEncField]) let getTupleReaderInfo (typ:Type,index:int) = - if index < 0 then invalidArg (nameof index) (SR.GetString2(SR.tupleIndexOutOfRange, typ.FullName, index.ToString())) + if index < 0 then invalidArg "index" (SR.GetString2(SR.tupleIndexOutOfRange, typ.FullName, index.ToString())) let props = typ.GetProperties(instancePropertyFlags ||| BindingFlags.Public) |> orderTupleProperties let get index = - if index >= props.Length then invalidArg (nameof index) (SR.GetString2(SR.tupleIndexOutOfRange, typ.FullName, index.ToString())) + if index >= props.Length then invalidArg "index" (SR.GetString2(SR.tupleIndexOutOfRange, typ.FullName, index.ToString())) props.[index] if index < tupleEncField then @@ -726,7 +726,7 @@ module internal Impl = let getFunctionTypeInfo (typ:Type) = - if not (isFunctionType typ) then invalidArg (nameof typ) (SR.GetString1(SR.notAFunctionType, typ.FullName)) + if not (isFunctionType typ) then invalidArg "typ" (SR.GetString1(SR.notAFunctionType, typ.FullName)) let tyargs = typ.GetGenericArguments() tyargs.[0], tyargs.[1] @@ -827,9 +827,9 @@ module internal Impl = let checkExnType (exceptionType, bindingFlags) = if not (isExceptionRepr (exceptionType,bindingFlags)) then if isExceptionRepr (exceptionType,bindingFlags ||| BindingFlags.NonPublic) then - invalidArg (nameof exceptionType) (SR.GetString1(SR.privateExceptionType, exceptionType.FullName)) + invalidArg "exceptionType" (SR.GetString1(SR.privateExceptionType, exceptionType.FullName)) else - invalidArg (nameof exceptionType) (SR.GetString1(SR.notAnExceptionType, exceptionType.FullName)) + invalidArg "exceptionType" (SR.GetString1(SR.notAnExceptionType, exceptionType.FullName)) let checkRecordType(argName,recordType,bindingFlags) = checkNonNull argName recordType; @@ -885,47 +885,47 @@ type UnionCaseInfo(typ: System.Type, tag:int) = type FSharpType = static member IsTuple(typ:Type) = - Impl.checkNonNull (nameof typ) typ; + Impl.checkNonNull "typ" typ; Impl.isTupleType typ static member IsRecord(typ:Type,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof typ) typ; + Impl.checkNonNull "typ" typ; Impl.isRecordType (typ,bindingFlags) static member IsUnion(typ:Type,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof typ) typ; + Impl.checkNonNull "typ" typ; let typ = Impl.getTypeOfReprType (typ ,BindingFlags.Public ||| BindingFlags.NonPublic) Impl.isUnionType (typ,bindingFlags) static member IsFunction(typ:Type) = - Impl.checkNonNull (nameof typ) typ; + Impl.checkNonNull "typ" typ; let typ = Impl.getTypeOfReprType (typ ,BindingFlags.Public ||| BindingFlags.NonPublic) Impl.isFunctionType typ static member IsModule(typ:Type) = - Impl.checkNonNull (nameof typ) typ; + Impl.checkNonNull "typ" typ; Impl.isModuleType typ static member MakeFunctionType(domain:Type,range:Type) = - Impl.checkNonNull (nameof domain) domain; - Impl.checkNonNull (nameof range) range; + Impl.checkNonNull "domain" domain; + Impl.checkNonNull "range" range; Impl.func.MakeGenericType [| domain; range |] static member MakeTupleType(types:Type[]) = - Impl.checkNonNull (nameof types) types; + Impl.checkNonNull "types" types; if types |> Array.exists (function null -> true | _ -> false) then - invalidArg (nameof types) (SR.GetString(SR.nullsNotAllowedInArray)) + invalidArg "types" (SR.GetString(SR.nullsNotAllowedInArray)) Impl.mkTupleType types static member GetTupleElements(tupleType:Type) = - Impl.checkTupleType(nameof tupleType,tupleType); + Impl.checkTupleType("tupleType",tupleType); Impl.getTupleTypeInfo tupleType static member GetFunctionElements(functionType:Type) = - Impl.checkNonNull (nameof functionType) functionType; + Impl.checkNonNull "functionType" functionType; let functionType = Impl.getTypeOfReprType (functionType ,BindingFlags.Public ||| BindingFlags.NonPublic) Impl.getFunctionTypeInfo functionType @@ -936,19 +936,19 @@ type FSharpType = static member GetUnionCases (unionType:Type,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof unionType) unionType; + Impl.checkNonNull "unionType" unionType; let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags) Impl.checkUnionType(unionType,bindingFlags); Impl.getUnionTypeTagNameMap(unionType,bindingFlags) |> Array.mapi (fun i _ -> UnionCaseInfo(unionType,i)) static member IsExceptionRepresentation(exceptionType:Type, ?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof exceptionType) exceptionType; + Impl.checkNonNull "exceptionType" exceptionType; Impl.isExceptionRepr(exceptionType,bindingFlags) static member GetExceptionFields(exceptionType:Type, ?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof exceptionType) exceptionType; + Impl.checkNonNull "exceptionType" exceptionType; Impl.checkExnType(exceptionType,bindingFlags); Impl.fieldPropsOfRecordType (exceptionType,bindingFlags) @@ -966,21 +966,21 @@ type FSharpValue = Impl.getRecordConstructor (recordType,bindingFlags) args static member GetRecordField(record:obj,info:PropertyInfo) = - Impl.checkNonNull (nameof info) info; - Impl.checkNonNull (nameof record) record; + Impl.checkNonNull "info" info; + Impl.checkNonNull "record" record; let reprty = record.GetType() - if not (Impl.isRecordType(reprty,BindingFlags.Public ||| BindingFlags.NonPublic)) then invalidArg (nameof record) (SR.GetString(SR.objIsNotARecord)); + if not (Impl.isRecordType(reprty,BindingFlags.Public ||| BindingFlags.NonPublic)) then invalidArg "record" (SR.GetString(SR.objIsNotARecord)); info.GetValue(record,null) static member GetRecordFields(record:obj,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof record) record; + Impl.checkNonNull "record" record; let typ = record.GetType() - if not (Impl.isRecordType(typ,bindingFlags)) then invalidArg (nameof record) (SR.GetString(SR.objIsNotARecord)); + if not (Impl.isRecordType(typ,bindingFlags)) then invalidArg "record" (SR.GetString(SR.objIsNotARecord)); Impl.getRecordReader (typ,bindingFlags) record static member PreComputeRecordFieldReader(info:PropertyInfo) = - Impl.checkNonNull (nameof info) info; + Impl.checkNonNull "info" info; (fun (obj:obj) -> info.GetValue(obj,null)) static member PreComputeRecordReader(recordType:Type,?bindingFlags) : (obj -> obj[]) = @@ -999,9 +999,9 @@ type FSharpValue = Impl.getRecordConstructorMethod(recordType,bindingFlags) static member MakeFunction(functionType:Type,implementation:(obj->obj)) = - Impl.checkNonNull (nameof functionType) functionType; - if not (Impl.isFunctionType functionType) then invalidArg (nameof functionType) (SR.GetString1(SR.notAFunctionType, functionType.FullName)); - Impl.checkNonNull (nameof implementation) implementation; + Impl.checkNonNull "functionType" functionType; + if not (Impl.isFunctionType functionType) then invalidArg "functionType" (SR.GetString1(SR.notAFunctionType, functionType.FullName)); + Impl.checkNonNull "implementation" implementation; let domain,range = Impl.getFunctionTypeInfo functionType let dynCloMakerTy = typedefof> let saverTy = dynCloMakerTy.MakeGenericType [| domain; range |] @@ -1010,53 +1010,53 @@ type FSharpValue = f implementation static member MakeTuple(tupleElements: obj[],tupleType:Type) = - Impl.checkNonNull (nameof tupleElements) tupleElements; - Impl.checkTupleType(nameof tupleType,tupleType) + Impl.checkNonNull "tupleElements" tupleElements; + Impl.checkTupleType("tupleType",tupleType) Impl.getTupleConstructor tupleType tupleElements static member GetTupleFields(tuple:obj) = // argument name(s) used in error message - Impl.checkNonNull (nameof tuple) tuple; + Impl.checkNonNull "tuple" tuple; let typ = tuple.GetType() - if not (Impl.isTupleType typ ) then invalidArg (nameof tuple) (SR.GetString1(SR.notATupleType, tuple.GetType().FullName)); + if not (Impl.isTupleType typ ) then invalidArg "tuple" (SR.GetString1(SR.notATupleType, tuple.GetType().FullName)); Impl.getTupleReader typ tuple static member GetTupleField(tuple:obj,index:int) = // argument name(s) used in error message - Impl.checkNonNull (nameof tuple) tuple; + Impl.checkNonNull "tuple" tuple; let typ = tuple.GetType() - if not (Impl.isTupleType typ ) then invalidArg (nameof tuple) (SR.GetString1(SR.notATupleType, tuple.GetType().FullName)); + if not (Impl.isTupleType typ ) then invalidArg "tuple" (SR.GetString1(SR.notATupleType, tuple.GetType().FullName)); let fields = Impl.getTupleReader typ tuple - if index < 0 || index >= fields.Length then invalidArg (nameof index) (SR.GetString2(SR.tupleIndexOutOfRange, tuple.GetType().FullName, index.ToString())); + if index < 0 || index >= fields.Length then invalidArg "index" (SR.GetString2(SR.tupleIndexOutOfRange, tuple.GetType().FullName, index.ToString())); fields.[index] static member PreComputeTupleReader(tupleType:Type) : (obj -> obj[]) = - Impl.checkTupleType(nameof tupleType,tupleType) + Impl.checkTupleType("tupleType",tupleType) Impl.getTupleReader tupleType static member PreComputeTuplePropertyInfo(tupleType:Type,index:int) = - Impl.checkTupleType(nameof tupleType,tupleType) + Impl.checkTupleType("tupleType",tupleType) Impl.getTupleReaderInfo (tupleType,index) static member PreComputeTupleConstructor(tupleType:Type) = - Impl.checkTupleType(nameof tupleType,tupleType) + Impl.checkTupleType("tupleType",tupleType) Impl.getTupleConstructor tupleType static member PreComputeTupleConstructorInfo(tupleType:Type) = - Impl.checkTupleType(nameof tupleType,tupleType) + Impl.checkTupleType("tupleType",tupleType) Impl.getTupleConstructorInfo (tupleType) static member MakeUnion(unionCase:UnionCaseInfo,args: obj [],?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof unionCase) unionCase; + Impl.checkNonNull "unionCase" unionCase; Impl.getUnionCaseConstructor (unionCase.DeclaringType,unionCase.Tag,bindingFlags) args static member PreComputeUnionConstructor (unionCase:UnionCaseInfo,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof unionCase) unionCase; + Impl.checkNonNull "unionCase" unionCase; Impl.getUnionCaseConstructor (unionCase.DeclaringType,unionCase.Tag,bindingFlags) static member PreComputeUnionConstructorInfo(unionCase:UnionCaseInfo, ?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof unionCase) unionCase; + Impl.checkNonNull "unionCase" unionCase; Impl.getUnionCaseConstructorMethod (unionCase.DeclaringType,unionCase.Tag,bindingFlags) static member GetUnionFields(obj:obj,unionType:Type,?bindingFlags) = @@ -1065,13 +1065,13 @@ type FSharpValue = match typ with | null -> match obj with - | null -> invalidArg (nameof obj) (SR.GetString(SR.objIsNullAndNoType)) + | null -> invalidArg "obj" (SR.GetString(SR.objIsNullAndNoType)) | _ -> obj.GetType() | _ -> typ //System.Console.WriteLine("typ1 = {0}",box unionType) let unionType = ensureType(unionType,obj) //System.Console.WriteLine("typ2 = {0}",box unionType) - Impl.checkNonNull (nameof unionType) unionType; + Impl.checkNonNull "unionType" unionType; let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags) //System.Console.WriteLine("typ3 = {0}",box unionType) Impl.checkUnionType(unionType,bindingFlags); @@ -1081,7 +1081,7 @@ type FSharpValue = static member PreComputeUnionTagReader(unionType: Type,?bindingFlags) : (obj -> int) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof unionType) unionType; + Impl.checkNonNull "unionType" unionType; let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags) Impl.checkUnionType(unionType,bindingFlags); Impl.getUnionTagReader (unionType ,bindingFlags) @@ -1089,20 +1089,20 @@ type FSharpValue = static member PreComputeUnionTagMemberInfo(unionType: Type,?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof unionType) unionType; + Impl.checkNonNull "unionType" unionType; let unionType = Impl.getTypeOfReprType (unionType ,bindingFlags) Impl.checkUnionType(unionType,bindingFlags); Impl.getUnionTagMemberInfo(unionType ,bindingFlags) static member PreComputeUnionReader(unionCase: UnionCaseInfo,?bindingFlags) : (obj -> obj[]) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof unionCase) unionCase; + Impl.checkNonNull "unionCase" unionCase; let typ = unionCase.DeclaringType Impl.getUnionCaseRecordReader (typ,unionCase.Tag,bindingFlags) static member GetExceptionFields(exn:obj, ?bindingFlags) = let bindingFlags = defaultArg bindingFlags BindingFlags.Public - Impl.checkNonNull (nameof exn) exn; + Impl.checkNonNull "exn" exn; let typ = exn.GetType() Impl.checkExnType(typ,bindingFlags); Impl.getRecordReader (typ,bindingFlags) exn diff --git a/src/fsharp/FlatList.fs b/src/fsharp/FlatList.fs index 3ed1c749de..9d38eedea2 100644 --- a/src/fsharp/FlatList.fs +++ b/src/fsharp/FlatList.fs @@ -60,7 +60,7 @@ module internal FlatList = let fold2 f acc (x:FlatList<_>) (y:FlatList<_>) = match x.array,y.array with | null,null -> acc - | null,_ | _,null -> invalidArg (nameof x) "mismatched list lengths" + | null,_ | _,null -> invalidArg "x" "mismatched list lengths" | arr1,arr2 -> Array.fold2 f acc arr1 arr2 let foldBack f (x:FlatList<_>) acc = @@ -71,13 +71,13 @@ module internal FlatList = let foldBack2 f (x:FlatList<_>) (y:FlatList<_>) acc = match x.array,y.array with | null,null -> acc - | null,_ | _,null -> invalidArg (nameof x) "mismatched list lengths" + | null,_ | _,null -> invalidArg "x" "mismatched list lengths" | arr1,arr2 -> Array.foldBack2 f arr1 arr2 acc let map2 f (x:FlatList<_>) (y:FlatList<_>) = match x.array,y.array with | null,null -> FlatList.Empty - | null,_ | _,null -> invalidArg (nameof x) "mismatched list lengths" + | null,_ | _,null -> invalidArg "x" "mismatched list lengths" | arr1,arr2 -> FlatList(Array.map2 f arr1 arr2) let forall f (x:FlatList<_>) = @@ -88,13 +88,13 @@ module internal FlatList = let forall2 f (x1:FlatList<_>) (x2:FlatList<_>) = match x1.array, x2.array with | null,null -> true - | null,_ | _,null -> invalidArg (nameof x1) "mismatched list lengths" + | null,_ | _,null -> invalidArg "x1" "mismatched list lengths" | arr1,arr2 -> Array.forall2 f arr1 arr2 let iter2 f (x1:FlatList<_>) (x2:FlatList<_>) = match x1.array, x2.array with | null,null -> () - | null,_ | _,null -> invalidArg (nameof x1) "mismatched list lengths" + | null,_ | _,null -> invalidArg "x1" "mismatched list lengths" | arr1,arr2 -> Array.iter2 f arr1 arr2 let partition f (x:FlatList<_>) = @@ -186,7 +186,7 @@ module internal FlatList = let zip (x:FlatList<_>) (y:FlatList<_>) = match x.array,y.array with | null,null -> FlatList.Empty - | null,_ | _,null -> invalidArg (nameof x) "mismatched list lengths" + | null,_ | _,null -> invalidArg "x" "mismatched list lengths" | arr1,arr2 -> FlatList(Array.zip arr1 arr2) #endif From 2d60881f2f9b12b305a3e547b9739c8f6d1a9223 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 14:54:37 +0100 Subject: [PATCH 12/21] Show we can find the name of members that are defined below --- src/fsharp/FSharp.Core.Unittests/NameOfTests.fs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 896dda30d1..192fbb2538 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -69,6 +69,13 @@ type BasicNameOfTests() = 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) From 8d2d721b6668fa55fdc972e9a656172e4f0e12fa Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 14:57:26 +0100 Subject: [PATCH 13/21] Prefix error cases with E_ --- ...OfAdditionExpr.fs => E_NameOfAdditionExpr.fs} | 0 ...iedFunction.fs => E_NameOfAppliedFunction.fs} | 0 ...NameOfDictLookup.fs => E_NameOfDictLookup.fs} | 0 .../{NameOfIntConst.fs => E_NameOfIntConst.fs} | 0 ...tion.fs => E_NameOfIntegerAppliedFunction.fs} | 0 ...on.fs => E_NameOfParameterAppliedFunction.fs} | 0 ...on.fs => E_NameOfPartiallyAppliedFunction.fs} | 0 ...meOfStringConst.fs => E_NameOfStringConst.fs} | 0 .../Expressions/DataExpressions/NameOf/env.lst | 16 ++++++++-------- tests/fsharpqa/Source/test.lst | 3 +-- 10 files changed, 9 insertions(+), 10 deletions(-) rename tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/{NameOfAdditionExpr.fs => E_NameOfAdditionExpr.fs} (100%) rename tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/{NameOfAppliedFunction.fs => E_NameOfAppliedFunction.fs} (100%) rename tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/{NameOfDictLookup.fs => E_NameOfDictLookup.fs} (100%) rename tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/{NameOfIntConst.fs => E_NameOfIntConst.fs} (100%) rename tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/{NameOfIntegerAppliedFunction.fs => E_NameOfIntegerAppliedFunction.fs} (100%) rename tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/{NameOfParameterAppliedFunction.fs => E_NameOfParameterAppliedFunction.fs} (100%) rename tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/{NameOfPartiallyAppliedFunction.fs => E_NameOfPartiallyAppliedFunction.fs} (100%) rename tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/{NameOfStringConst.fs => E_NameOfStringConst.fs} (100%) diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAdditionExpr.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAdditionExpr.fs similarity index 100% rename from tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAdditionExpr.fs rename to tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAdditionExpr.fs diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAppliedFunction.fs similarity index 100% rename from tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfAppliedFunction.fs rename to tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAppliedFunction.fs diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfDictLookup.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfDictLookup.fs similarity index 100% rename from tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfDictLookup.fs rename to tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfDictLookup.fs diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntConst.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntConst.fs similarity index 100% rename from tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntConst.fs rename to tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntConst.fs diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntegerAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntegerAppliedFunction.fs similarity index 100% rename from tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfIntegerAppliedFunction.fs rename to tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntegerAppliedFunction.fs diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfParameterAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfParameterAppliedFunction.fs similarity index 100% rename from tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfParameterAppliedFunction.fs rename to tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfParameterAppliedFunction.fs diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfPartiallyAppliedFunction.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfPartiallyAppliedFunction.fs similarity index 100% rename from tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfPartiallyAppliedFunction.fs rename to tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfPartiallyAppliedFunction.fs diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfStringConst.fs b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfStringConst.fs similarity index 100% rename from tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/NameOfStringConst.fs rename to tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfStringConst.fs diff --git a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst index 33c0ef0344..4470131277 100644 --- a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst @@ -1,8 +1,8 @@ - SOURCE=NameOfIntConst.fs # NameOfIntConst.fs - SOURCE=NameOfStringConst.fs # NameOfStringConst.fs - SOURCE=NameOfAppliedFunction.fs # NameOfAppliedFunction.fs - SOURCE=NameOfIntegerAppliedFunction.fs # NameOfIntegerAppliedFunction.fs - SOURCE=NameOfPartiallyAppliedFunction.fs # NameOfPartiallyAppliedFunction.fs - SOURCE=NameOfDictLookup.fs # NameOfDictLookup.fs - SOURCE=NameOfAdditionExpr.fs # NameOfAdditionExpr.fs - SOURCE=NameOfParameterAppliedFunction.fs # NameOfParameterAppliedFunction.fs \ No newline at end of file + 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 \ No newline at end of file diff --git a/tests/fsharpqa/Source/test.lst b/tests/fsharpqa/Source/test.lst index cfdb6a864d..50bd2dc22b 100644 --- a/tests/fsharpqa/Source/test.lst +++ b/tests/fsharpqa/Source/test.lst @@ -235,8 +235,7 @@ Conformance08 Conformance\UnitsOfMeasure\Parenthesis Conformance08 Conformance\UnitsOfMeasure\Parsing Conformance08 Conformance\UnitsOfMeasure\TypeChecker Conformance08 Conformance\UnitsOfMeasure\WithOOP - -Conformance09 Conformance\Expressions\DataExpressions\NameOf +Conformance08 Conformance\Expressions\DataExpressions\NameOf NoHostedCompiler,TypeProviders01 TypeProviders\Arrays NoHostedCompiler,TypeProviders01 ..\..\..\testsprivate\fsharpqa\Source\TypeProviders\BuiltIn\EdmxFile From 0a92ef495b9b445a3584e751550b26a6e69c22b0 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 15:04:36 +0100 Subject: [PATCH 14/21] Show user-defined nameof wins. --- src/fsharp/FSharp.Core.Unittests/NameOfTests.fs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 192fbb2538..78216b7af6 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -145,4 +145,13 @@ type OperatorNameTests() = [] member this.``lookup name of nameof operator`` () = let b = nameof(nameof) - Assert.AreEqual("NameOf",b) \ No newline at end of file + Assert.AreEqual("NameOf",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 From 0ba200b857a548d607b334f719944e5822ebcca6 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 15:20:40 +0100 Subject: [PATCH 15/21] Don' report get_ for properties in nameof --- src/fsharp/FSharp.Core.Unittests/NameOfTests.fs | 4 ++-- src/fsharp/check.fs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 78216b7af6..7856fd8f8c 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -99,12 +99,12 @@ type BasicNameOfTests() = [] member this.``member property name`` () = let b = nameof(this.MemberProperty) - Assert.AreEqual("get_MemberProperty",b) + Assert.AreEqual("MemberProperty",b) [] member this.``static property name`` () = let b = nameof(BasicNameOfTests.StaticProperty) - Assert.AreEqual("get_StaticProperty",b) + Assert.AreEqual("StaticProperty",b) [] member this.``nameof local property with encapsulated name`` () = diff --git a/src/fsharp/check.fs b/src/fsharp/check.fs index 1dc53ce5ca..ebf81552bd 100644 --- a/src/fsharp/check.fs +++ b/src/fsharp/check.fs @@ -433,13 +433,13 @@ let extractNameOf args = | 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) + 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) + Some(r.CompiledName.Substring(4)) else None // the function was applied | Expr.Let(_,Expr.Val(r,_,_),_,_) -> Some(r.CompiledName) From 827bef8574b67d150c1d874cf3d4483e67eade17 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 16:08:52 +0100 Subject: [PATCH 16/21] Show that nameof can't be used as a function --- .../DataExpressions/NameOf/E_NameOfAsAFunction.fs | 7 +++++++ .../Conformance/Expressions/DataExpressions/NameOf/env.lst | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAsAFunction.fs 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/env.lst b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst index 4470131277..449a4114be 100644 --- a/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst +++ b/tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/env.lst @@ -5,4 +5,5 @@ 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 \ No newline at end of file + SOURCE=E_NameOfParameterAppliedFunction.fs # E_NameOfParameterAppliedFunction.fs + SOURCE=E_NameOfAsAFunction.fs # E_NameOfAsAFunction.fs \ No newline at end of file From 7c1713cb1629b3e27d3c5cab51c3372b338c241d Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 16:14:54 +0100 Subject: [PATCH 17/21] Show how we can use nameof in pattern matching --- src/fsharp/FSharp.Core.Unittests/NameOfTests.fs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 7856fd8f8c..6e52d6ba6f 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -147,6 +147,16 @@ type OperatorNameTests() = let b = nameof(nameof) Assert.AreEqual("NameOf",b) +[] +type PatternMatchingOfOperatorNameTests() = + member this.Method1(i:int) = () + + [] + member this.``use it as a match case`` () = + match "Method1" with + | x when x = nameof(this.Method1) -> () + | _ -> Assert.Fail("not expected") + [] type UserDefinedNameOfTests() = [] From fa063b08e5a2c3279465090002eef7f4dcaaff8f Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 16:42:34 +0100 Subject: [PATCH 18/21] Use nameof in quotation --- src/fsharp/FSharp.Core.Unittests/NameOfTests.fs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 6e52d6ba6f..791f564761 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -157,6 +157,17 @@ type PatternMatchingOfOperatorNameTests() = | 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 UserDefinedNameOfTests() = [] From 4adfe455e3788786b95b433acec7deb3d39fa709 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 18 Nov 2014 17:51:02 +0100 Subject: [PATCH 19/21] Add a generic function as nameof test --- src/fsharp/FSharp.Core.Unittests/NameOfTests.fs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 791f564761..dd32c83d6a 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -168,6 +168,14 @@ type NameOfOperatorInQuotations() = @> () +[] +type NameOfOperatorForGenerics() = + [] + member this.``use it in a generic function`` () = + let fullyGeneric x = x + let b = nameof(fullyGeneric) + Assert.AreEqual("fullyGeneric",b) + [] type UserDefinedNameOfTests() = [] From e74f2abb868ca424cffbd44571c4998fa366827c Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 19 Nov 2014 09:33:39 +0100 Subject: [PATCH 20/21] Show methods with get_ work in nameof --- src/fsharp/FSharp.Core.Unittests/NameOfTests.fs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index dd32c83d6a..6cbd5c6e92 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -106,6 +106,20 @@ type BasicNameOfTests() = 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 From 005e740ad1d8d6cc50d7786430c8d4b4021c28c1 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 19 Nov 2014 16:47:53 +0100 Subject: [PATCH 21/21] Better structure in nameof tests --- .../FSharp.Core.Unittests/NameOfTests.fs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs index 6cbd5c6e92..468a3ebfae 100644 --- a/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs +++ b/src/fsharp/FSharp.Core.Unittests/NameOfTests.fs @@ -81,16 +81,6 @@ type BasicNameOfTests() = let b = nameof(BasicNameOfTests.StaticMethod) Assert.AreEqual("StaticMethod",b) - [] - 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) - [] member this.``class member lookup`` () = let b = nameof(localConstant) @@ -136,6 +126,18 @@ type MethodGroupTests() = 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() = @@ -166,7 +168,7 @@ type PatternMatchingOfOperatorNameTests() = member this.Method1(i:int) = () [] - member this.``use it as a match case`` () = + member this.``use it as a match case guard`` () = match "Method1" with | x when x = nameof(this.Method1) -> () | _ -> Assert.Fail("not expected")