-
Notifications
You must be signed in to change notification settings - Fork 845
Support CallerArgumentExpression
#17519
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
base: main
Are you sure you want to change the base?
Conversation
❗ Release notes requiredCaution No release notes found for the changed paths (see table below). Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format. The following format is recommended for this repository:
If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request. You can open this PR in browser to add release notes: open in github.dev
|
…Tangent-90/fsharp into SupportCallerArgumentExpression
|
Here I encounter a problem about #1 "C:\\Program.fs"
System.ArgumentNullException.ThrowIfNullOrWhiteSpace(" ") // will failed to build
// And more complicated case, repeat the file name and line number
#1 "C:\\Program.fs"
System.ArgumentNullException.ThrowIfNullOrWhiteSpace(" ") // will failed to buildSo here I want to get the original |
Simplify code
add warning read the new line mark
…Tangent-90/fsharp into SupportCallerArgumentExpression
src/Compiler/Utilities/range.fs
Outdated
| | _ -> String.Empty | ||
| } | ||
|
|
||
| let getCodeText (m: range) = |
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.
I wonder whether it would be possible to use ISourceText.GetSubTextString instead of all of this. I think the ISourceText for a given file will usually already be cached when this functionality is needed.
I think in theory the source text is available on cenv.tcSink.CurrentSink.Value.CurrentSourceText.Value, but maybe there's a better way to get it, or a better way to bring it in scope for this change.
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.
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.
Maybe it would make sense to pass it in, then, as is done when checking format strings:
fsharp/src/Compiler/Checking/NameResolution.fs
Lines 1777 to 1779 in 0a715a5
| type FormatStringCheckContext = | |
| { SourceText: ISourceText | |
| LineStartPositions: int[] } |
fsharp/src/Compiler/Checking/CheckFormatStrings.fs
Lines 67 to 73 in 0a715a5
| let makeFmts (context: FormatStringCheckContext) (fragRanges: range list) (fmt: string) = | |
| // Splits the string on interpolation holes based on fragment ranges. | |
| // Returns a list of tuples in the form of: offset * fragment as a string * original range of the fragment | |
| // where "offset" is the offset between beginning of the original range and where the string content begins | |
| let numFrags = fragRanges.Length | |
| let sourceText = context.SourceText |
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.
Maybe it would make sense to pass it in, then, as is done when checking format strings:
I guess maybe that's the same source text as in the sink... But still, maybe there's somewhere else we could put it.
|
@T-Gro Hi there, I cannot access the Azure to see the test result. Could you please grant me the permission? The page said:
|
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.
Pull request overview
This PR implements support for the CallerArgumentExpression attribute in F#, as specified in RFC FS-1149. The feature allows method parameters to capture the source code text of arguments passed at call sites, similar to the C# feature. Additionally, it enhances the assert keyword to automatically pass the assertion expression as a string parameter when available.
Changes:
- Adds
CallerArgumentExpressionas a new language feature and caller info type - Implements source text tracking in lexbuf and throughout the compilation pipeline
- Updates method call resolution to pass argument expression text to annotated parameters
- Enhances
assertexpressions to pass expression text toDebug.Assertmethods - Adds comprehensive tests for various scenarios including F#/C# interop, computation expressions, and edge cases
Reviewed changes
Copilot reviewed 48 out of 49 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Compiler/Facilities/LanguageFeatures.fs/fsi |
Adds SupportCallerArgumentExpression feature flag |
src/Compiler/Facilities/prim-lexing.fs/fsi |
Adds SourceText tracking to LexBuffer for capturing source code |
src/Compiler/TypedTree/TcGlobals.fs/fsi |
Adds attrib_CallerArgumentExpressionAttribute to supported attributes |
src/Compiler/TypedTree/TypedTreeOps.fs/fsi |
Adds helpers to find attributes by name for user-defined CallerArgumentExpression |
src/Compiler/Checking/infos.fs/fsi |
Extends CallerInfo DU with CallerArgumentExpression case and implements precedence logic |
src/Compiler/Checking/MethodCalls.fs/fsi |
Implements argument expression text capture and passing to optional parameters |
src/Compiler/Checking/CheckExpressions.fs |
Enhances assert to pass expression text as second argument |
src/Compiler/Checking/PostInferenceChecks.fs |
Adds validation for CallerArgumentExpression parameters |
src/Compiler/Checking/CheckDeclarations.fs/fsi |
Threads source text through checking pipeline |
src/Compiler/Checking/CheckBasics.fs/fsi |
Adds SourceText field to TcFileState |
src/Compiler/Driver/ParseAndCheckInputs.fs/fsi |
Updates signatures to carry source text with parsed inputs |
src/Compiler/Driver/fsc.fs |
Updates driver to handle source text in inputs |
src/Compiler/Driver/ScriptClosure.fs/fsi |
Adds source text tracking to load closures |
src/Compiler/Service/* |
Updates service layer to thread source text through APIs |
src/Compiler/Interactive/fsi.fs |
Updates FSI to support CallerArgumentExpression in interactive scenarios |
src/Compiler/FSComp.txt |
Adds new diagnostic messages for CallerArgumentExpression feature |
src/Compiler/xlf/*.xlf |
Adds localization strings for new diagnostics |
tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs |
Removes CallerArgumentExpression from unsupported list |
tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/CustomAttributes/CallerArgumentExpression/CallerArgumentExpression.fs |
Comprehensive tests for the feature |
tests/FSharp.Compiler.ComponentTests/Conformance/Expressions/ApplicationExpressions/AssertExpression.fs |
Tests for enhanced assert expressions |
docs/release-notes/* |
Documents the new feature |
Make not support CAE error to be info
|
It needs modify the parser to make it knows the type System.Object with
member this.A([<CallerArgumentExpression "this">] ?arg: string) = arg
// ^^^^ ^^^^I tried make it stores the fsharp/src/Compiler/SyntaxTree/SyntaxTreeOps.fs Lines 735 to 746 in c33bedd
|

Description
Implements fsharp/fslang-suggestions#966, #18489
RFC FS-1149-support-CallerArgumentExpression.md, FS-1332-assert-keyword-enhancement.md
Checklist