Skip to content

nameof fixes - #9498

Merged
KevinRansom merged 1 commit into
dotnet:masterfrom
dsyme:no2
Jun 18, 2020
Merged

KevinRansom merged 1 commit into
dotnet:masterfrom
dsyme:no2

Conversation

@dsyme

@dsyme dsyme commented Jun 18, 2020

Copy link
Copy Markdown
Contributor
  1. Allow nameof<'T> for name of generic parameters

  2. Allow nameof(Unchecked.defaultof<C>.Property) for instance members

I checked and literals are already allowed:

> let [<Literal>] x = nameof(id);;
val x : string = "id"

> x;;
val it : string = "id"

I think this resolves all issues in the nameof design but @TIHan and @cartermp will check

May require fixing up some tests

Comment thread src/absil/illib.fs
mn 0 xs
let count pred xs = List.fold (fun n x -> if pred x then n+1 else n) 0 xs

let headAndTail l =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally removed by @forki in another PR and he cleaned up (and simplified) some places where it was being used. Is it necessary to add back here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved Don's cheese ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a useful function :-)


val (|TypeDefOfExpr|_|) : TcGlobals -> Expr -> TType option

val isNameOfValRef: TcGlobals -> ValRef -> bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: this should probably be moved down after all of the active patterns

let b = nameof(Unchecked.defaultof<BasicNameOfTests>.MemberMethod)
Assert.AreEqual("MemberMethod", b)

member this.``can get name of method type parameter``<'TTT> () =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add this, perhaps as a test in another file

type C<'DootDoot>() =
    member _.Name() = nameof<'DootDoot>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes agreed

@cartermp

Copy link
Copy Markdown
Contributor

@dsyme what about this?

let rec [<Literal>] x = nameof(x)

@KevinRansom
KevinRansom merged commit 8d048d8 into dotnet:master Jun 18, 2020
@cartermp

Copy link
Copy Markdown
Contributor

The literal business is "resolved" insofar as it requires a langauge suggestion

nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants