-
Notifications
You must be signed in to change notification settings - Fork 825
[WIP] [FS-1003] Nameof operator reimplementation #2290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
vasily-kirichenko
wants to merge
34
commits into
dotnet:master
from
vasily-kirichenko:nameof-operator
Closed
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
d380a0e
substitute 'nameof(<long ident>)` with `Conts(<long ident as string l…
223d313
Implementing basic nameof and typenameof operators
529cc6f
Apply feedback
f3c4ba5
Revert "Apply feedback"
8fd0392
Revert "Implementing basic nameof and typenameof operators"
77c8f77
revert nameof and typenameof functions to FSharp.Core
vasily-kirichenko 3070c1d
wip
vasily-kirichenko b3e712d
it works
vasily-kirichenko 6c6e3b5
Merge remote-tracking branch 'origin/master' into nameof-operator
7832be5
refactoring
6581790
make it work on simple `Ident`s
0f5165f
use proper error message
22898ad
restrict using `nameof` operator as first class
e5033af
remove `typenameof` bits
1ad0a0e
nameof(typeof<_>) works
c9a64b2
Merge branch 'master' into nameof-operator
vasily-kirichenko 5657759
fix QA tests
vasily-kirichenko b26994c
Merge branch 'master' into nameof-operator
vasily-kirichenko a732de0
remove nameof function form FSharp.Core
vasily-kirichenko b29fe57
Merge remote-tracking branch 'origin/master' into nameof-operator
vasily-kirichenko b7763a6
Revert "remove nameof function form FSharp.Core"
vasily-kirichenko 906a934
Try to resolve the `nameof` operator argument to prevent passing anyt…
vasily-kirichenko a770e3c
nameof works on generic types
vasily-kirichenko 067955a
fix error range in case of wrong `nameof`operator argument
vasily-kirichenko bfcc390
notify name resolution sink about nameof operator argument Item in or…
vasily-kirichenko 6a92a80
fully type check `nameof` argument
vasily-kirichenko bcec600
try to type check arg again
vasily-kirichenko f64b3c5
Merge remote-tracking branch 'origin/master' into nameof-operator
0c1cad2
type check `nameof` argument more carefully
vasily-kirichenko 15bf862
Merge remote-tracking branch 'vasily-kirichenko/nameof-operator' into…
vasily-kirichenko 5b72f32
Merge remote-tracking branch 'origin/master' into nameof-operator
vasily-kirichenko ceb7731
Merge branch 'master' into nameof-operator
vasily-kirichenko 588de2e
factor tcExpr to top level function
vasily-kirichenko f2ae00f
Merge remote-tracking branch 'origin/master' into nameof-operator
vasily-kirichenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
228 changes: 228 additions & 0 deletions
228
src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Core/NameOfTests.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
// 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 | ||
|
||
[<TestFixture>] | ||
type BasicNameOfTests() = | ||
let localConstant = 23 | ||
member this.MemberMethod() = 0 | ||
member this.MemberProperty = this.MemberMethod() | ||
static member StaticMethod() = 0 | ||
static member StaticProperty = BasicNameOfTests.StaticMethod() | ||
|
||
[<Test>] | ||
member this.``local variable name lookup`` () = | ||
let a = 0 | ||
let result = nameof a | ||
Assert.AreEqual("a",result) | ||
Assert.AreEqual("result",nameof result) | ||
|
||
[<Test>] | ||
member this.``local int function name`` () = | ||
let myFunction x = 0 * x | ||
let b = nameof myFunction | ||
Assert.AreEqual("myFunction",b) | ||
|
||
[<Test>] | ||
member this.``local curried function name`` () = | ||
let curriedFunction x y = x * y | ||
let b = nameof curriedFunction | ||
Assert.AreEqual("curriedFunction",b) | ||
|
||
[<Test>] | ||
member this.``local tupled function name`` () = | ||
let tupledFunction(x,y) = x * y | ||
let b = nameof tupledFunction | ||
Assert.AreEqual("tupledFunction",b) | ||
|
||
[<Test>] | ||
member this.``local unit function name`` () = | ||
let myFunction() = 1 | ||
let b = nameof(myFunction) | ||
Assert.AreEqual("myFunction",b) | ||
|
||
[<Test>] | ||
member this.``local function parameter name`` () = | ||
let myFunction parameter1 = nameof parameter1 | ||
|
||
Assert.AreEqual("parameter1",myFunction "x") | ||
|
||
[<Test>] | ||
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) | ||
|
||
[<Test>] | ||
member this.CanGetNameFromInsideAMember () = | ||
let b = nameof(this.CanGetNameFromInsideAMember) | ||
Assert.AreEqual("CanGetNameFromInsideAMember",b) | ||
|
||
[<Test>] | ||
member this.``member function name`` () = | ||
let b = nameof(this.MemberMethod) | ||
Assert.AreEqual("MemberMethod",b) | ||
|
||
[<Test>] | ||
member this.``member function which is defined below`` () = | ||
let b = nameof(this.MemberMethodDefinedBelow) | ||
Assert.AreEqual("MemberMethodDefinedBelow",b) | ||
|
||
member this.MemberMethodDefinedBelow(x,y) = x * y | ||
|
||
[<Test>] | ||
member this.``static member function name`` () = | ||
let b = nameof(BasicNameOfTests.StaticMethod) | ||
Assert.AreEqual("StaticMethod",b) | ||
|
||
[<Test>] | ||
member this.``class member lookup`` () = | ||
let b = nameof(localConstant) | ||
Assert.AreEqual("localConstant",b) | ||
|
||
[<Test>] | ||
member this.``member property name`` () = | ||
let b = nameof(this.MemberProperty) | ||
Assert.AreEqual("MemberProperty",b) | ||
|
||
[<Test>] | ||
member this.``static property name`` () = | ||
let b = nameof(BasicNameOfTests.StaticProperty) | ||
Assert.AreEqual("StaticProperty",b) | ||
|
||
member this.get_XYZ() = 1 | ||
|
||
[<Test>] | ||
member this.``member method starting with get_`` () = | ||
let b = nameof(this.get_XYZ) | ||
Assert.AreEqual("get_XYZ",b) | ||
|
||
static member get_SXYZ() = 1 | ||
|
||
[<Test>] | ||
member this.``static method starting with get_`` () = | ||
let b = nameof(BasicNameOfTests.get_SXYZ) | ||
Assert.AreEqual("get_SXYZ",b) | ||
|
||
[<Test>] | ||
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) | ||
|
||
[<TestFixture>] | ||
type MethodGroupTests() = | ||
member this.MethodGroup() = () | ||
member this.MethodGroup(i:int) = () | ||
|
||
member this.MethodGroup1(i:int, f:float, s:string) = 0 | ||
member this.MethodGroup1(f:float, l:int64) = "foo" | ||
member this.MethodGroup1(u:unit -> unit -> int, h: unit) : unit = () | ||
|
||
[<Test>] | ||
member this.``single argument method group name lookup`` () = | ||
let b = nameof(this.MethodGroup) | ||
Assert.AreEqual("MethodGroup",b) | ||
|
||
[<Test>] | ||
member this.``multiple argument method group name lookup`` () = | ||
let b = nameof(this.MethodGroup1) | ||
Assert.AreEqual("MethodGroup1",b) | ||
|
||
[<TestFixture>] | ||
type FrameworkMethodTests() = | ||
[<Test>] | ||
member this.``library function name`` () = | ||
let b = nameof(List.map) | ||
Assert.AreEqual("map",b) | ||
|
||
[<Test>] | ||
member this.``static class function name`` () = | ||
let b = nameof(Tuple.Create) | ||
Assert.AreEqual("Create",b) | ||
|
||
type CustomUnionType = | ||
| OptionA of string | ||
| OptionB of int * string | ||
|
||
[<TestFixture>] | ||
type OperatorNameTests() = | ||
|
||
[<Test>] | ||
member this.``lookup name of typeof operator`` () = | ||
let b = nameof(typeof<int>) | ||
Assert.AreEqual("typeof",b) | ||
|
||
[<Test>] | ||
member this.``lookup name of + operator`` () = | ||
let b = nameof(+) | ||
Assert.AreEqual("op_Addition",b) | ||
|
||
[<Test>] | ||
member this.``lookup name of |> operator`` () = | ||
let a = nameof(|>) | ||
Assert.AreEqual("op_PipeRight",a) | ||
let b = nameof(op_PipeRight) | ||
Assert.AreEqual("op_PipeRight",b) | ||
|
||
[<Test>] | ||
member this.``lookup name of nameof operator`` () = | ||
let b = nameof(nameof) | ||
Assert.AreEqual("nameof",b) | ||
|
||
[<TestFixture>] | ||
type PatternMatchingOfOperatorNameTests() = | ||
member this.Method1(i:int) = () | ||
|
||
[<Test>] | ||
member this.``use it as a match case guard`` () = | ||
match "Method1" with | ||
| x when x = nameof(this.Method1) -> () | ||
| _ -> Assert.Fail("not expected") | ||
|
||
[<TestFixture>] | ||
type NameOfOperatorInQuotations() = | ||
[<Test>] | ||
member this.``use it in a quotation`` () = | ||
let q = | ||
<@ | ||
let f(x:int) = nameof x | ||
f 20 | ||
@> | ||
() | ||
|
||
[<TestFixture>] | ||
type NameOfOperatorForGenerics() = | ||
[<Test>] | ||
member this.``use it in a generic function`` () = | ||
let fullyGeneric x = x | ||
let b = nameof(fullyGeneric) | ||
Assert.AreEqual("fullyGeneric",b) | ||
|
||
[<Test>] | ||
member this.``lookup name of a generic class`` () = | ||
let b = nameof System.Collections.Generic.List<int> | ||
Assert.AreEqual("List",b) | ||
|
||
[<TestFixture>] | ||
type UserDefinedNameOfTests() = | ||
[<Test>] | ||
member this.``userdefined nameof should shadow the operator`` () = | ||
let nameof x = "test" + x.ToString() | ||
|
||
let y = nameof 1 | ||
Assert.AreEqual("test1",y) | ||
|
||
type Person = | ||
{ Name : string | ||
Age : int } | ||
member __.Update(fld : string, value : obj) = | ||
match fld with | ||
| x when x = nameof __.Name -> { __ with Name = string value } | ||
| x when x = nameof __.Age -> { __ with Age = value :?> int } | ||
| _ -> __ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't "First-class uses" not be "First-class use"?