-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support [<CallerArgumentExpression>] #966
Comments
Note F# does let you use type B() =
static member M([<ReflectedDefinition>] x: Quotations.Expr<int>) = printfn "x = %A" x
B.M(1+1) gives x = Call (None, op_Addition, [Value (1), Value (1)]) You can also add "WithValue" which both evaluates the expression and gives its quotation: type B() =
static member M([<ReflectedDefinition(includeValue=true)>] x: Quotations.Expr<int>) = printfn "x = %A" x
B.M(1+1) gives x = WithValue (2, Call (None, op_Addition, [Value (1), Value (1)])) For example you can get both a closure and the quotation of the closure. |
But that is not searchable in the codebase and is too verbose for debugging purposes. |
Yes, capturing the string has different properties |
This will be in C# vNext: dotnet/roslyn#51952 |
It has since gotten into C# 10. Here's some docs and use cases. PS: Championing issue is still open only because ECMA Spec isn't written yet. |
Marked as approved-in-principle |
How can we implement the feature? At present, the compiler does not store the source code during compilation (or maybe I didn't find out), so it cannot obtain the original source text of the argument... So there might be two way to make it. One is to read the source text through the FileSystem, by this way we can gain the original texts, but may be unusable in the fsi (since the filename is default to "stdin"). The other is to convert the expressions of the argument into code text. |
Champion "CallerArgumentExpression" is currently in the C# team's working set.
I propose we support this attribute, which has been present since .NET Core 3.0. We can match this attribute by namespace so that it can be defined even when outside .NET Core.
The motivation, pros, and cons can be seen in the C# proposal. To summarize, this allows developers to capture the expressions passed to a method, to enable better error messages in diagnostic/testing APIs and reduce keystrokes.
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M
Related suggestions: #463 - F# compiler should support CallerLineNumber, CallerFilePath etc (Completed for F# 4.1)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: