-
Notifications
You must be signed in to change notification settings - Fork 824
Allow typed bindings(and!) in CE without parentheses #18682
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 required
|
and!
typed bindingsThere 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.
@edgarfgp Thanks for this! Could you also cover error cases in the grammar, please? If unified with the let
parsing, we could probably get a lot of recovery for free as well.
11a44ca
to
2e074f0
Compare
tests/service/data/SyntaxTree/Binding/ColonBeforeReturnTypeIsPartOfTrivia.fs.bsl
Outdated
Show resolved
Hide resolved
2e074f0
to
c03a338
Compare
…sharp into allow-and-bang-typed-bindings
fdd8074
to
9e50380
Compare
/azp run |
Commenter does not have sufficient privileges for PR 18682 in repo dotnet/fsharp |
009b91b
to
02fecdf
Compare
34ec912
to
fd7e890
Compare
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 allowing type annotations on let!
, use!
, and and!
bindings in computation expressions without requiring parentheses, in line with RFC FS-1329.
- Grammar and AST updates introduce unified parsing rules (
bindingPatternWithOptType
,ceBindingCore
) and new helper functions (mkLetExpression
,mkAndBang
) to build the correct AST nodes. - Language feature renamed to
AllowTypedLetUseAndBang
and its usage updated in both the feature registry and computation expression checker. - Extensive updates to parser-service tests, component tests, and release notes ensure coverage of the new scenarios and adjust expected diagnostics.
Reviewed Changes
Copilot reviewed 86 out of 86 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/service/data/SyntaxTree/SynType/Typed UseBang.fs / .fs.bsl | Updated parser-service test cases for typed use! scenarios, adjusting expected parse errors and AST shapes. |
tests/service/data/SyntaxTree/SynType/Typed LetBang AndBang.fs / .fs.bsl | Extended test suite across 18+ variations to cover typed let! , and! , patterns, lists, tuples, unions, etc. |
tests/service/data/SyntaxTree/Pattern/Typed - Missing type*.fs.bsl | Added missing Expecting type parse errors to existing pattern tests. |
tests/service/data/SyntaxTree/Member/Member 13.fs.bsl | Injected Expecting type parse error for incomplete member definitions. |
tests/service/data/SyntaxTree/Expression/Yield* / Return*!*.fs.bsl | Added Expecting type parse errors to yield/return tests for completeness. |
tests/service/data/SyntaxTree/ComputationExpression/SynExprAndBangRange.fs.bsl | Fixed ranges for SynExprAndBang to reflect trimmed spans after grammar changes. |
tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs | Extended CE component tests to cover and! type-annotation behavior and adjusted diagnostic positions. |
tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/*.fs | Adjusted diagnostic column spans in UseBangBindingsVersion9 tests to match new grammar. |
src/Compiler/pars.fsy | Introduced bindingPatternWithOptType and ceBindingCore , updated and! grammar rules and error recovery. |
src/Compiler/SyntaxTree/ParseHelpers.fsi | Added mkLetExpression and mkAndBang signatures; replaced old mkLocalBindings . |
src/Compiler/SyntaxTree/ParseHelpers.fs | Implemented mkLetExpression and mkAndBang , removed mkLocalBindings , unified binding AST creation. |
src/Compiler/Facilities/LanguageFeatures.fsi / .fs | Renamed feature flag to AllowTypedLetUseAndBang and updated version support. |
src/Compiler/Checking/Expressions/CheckComputationExpressions.fs | Updated computation expression checker to use the new AllowTypedLetUseAndBang language feature. |
docs/release-notes/.Language/preview.md | Added entry for preview support of and! type annotations without parentheses. |
docs/release-notes/.FSharp.Compiler.Service/10.0.100.md | Updated release notes to include and! in the feature description. |
Comments suppressed due to low confidence (2)
src/Compiler/SyntaxTree/ParseHelpers.fs:871
- [nitpick] Consider adding XML documentation comments for mkAndBang in the .fsi file to explain its parameters and use in computation expressions.
let mkAndBang (mKeyword: range, pat: SynPat, rhs: SynExpr, mWhole: range, mEquals: range, mIn: range option) =
src/Compiler/pars.fsy:3523
- [nitpick] It may help to expand this comment with an example of how bindingPatternWithOptType interacts with ceBindingCore and the new
and!
rules, improving future maintainability.
// This rule unifies the pattern parsing for both regular 'let' bindings and (let!, use!, and!)
Description
Allow computation expression (CE) bindings (
let!
,use!
,and!
) to accept type annotations without requiring parentheses.Continuation of #18508
Implements RFC FS-1329: fsharp/fslang-design#802
Introduces significant grammar unification:
bindingPatternWithOptType
andceBindingCore
mkLetExpression
andmkAndBang
AllowTypedLetUseAndBang
The above rule unification will allow us to remove in a separate PR
LetOrUseBang
, adding boolenisComputed
property(true for let!/use!, false for let/use) toLetOrUse
.Checklist