- Notifications
You must be signed in to change notification settings - Fork825
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 ourterms of service andprivacy 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?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
github-actionsbot commentedJun 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
❗ 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 thelet
parsing, we could probably get a lot of recovery for free as well.
Uh oh!
There was an error while loading.Please reload this page.
11a44ca
to2e074f0
Comparetests/service/data/SyntaxTree/Binding/ColonBeforeReturnTypeIsPartOfTrivia.fs.bsl OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
2e074f0
toc03a338
Compare…sharp into allow-and-bang-typed-bindings
fdd8074
to9e50380
Compare/azp run |
Commenter does not have sufficient privileges for PR 18682 in repo dotnet/fsharp |
009b91b
to02fecdf
Compare34ec912
tofd7e890
CompareThere 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 onlet!
,use!
, andand!
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 typeduse! 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 typedlet! ,and! , patterns, lists, tuples, unions, etc. |
tests/service/data/SyntaxTree/Pattern/Typed - Missing type*.fs.bsl | Added missingExpecting type parse errors to existing pattern tests. |
tests/service/data/SyntaxTree/Member/Member 13.fs.bsl | InjectedExpecting type parse error for incomplete member definitions. |
tests/service/data/SyntaxTree/Expression/Yield* / Return*!*.fs.bsl | AddedExpecting type parse errors to yield/return tests for completeness. |
tests/service/data/SyntaxTree/ComputationExpression/SynExprAndBangRange.fs.bsl | Fixed ranges forSynExprAndBang to reflect trimmed spans after grammar changes. |
tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs | Extended CE component tests to coverand! type-annotation behavior and adjusted diagnostic positions. |
tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/*.fs | Adjusted diagnostic column spans inUseBangBindingsVersion9 tests to match new grammar. |
src/Compiler/pars.fsy | IntroducedbindingPatternWithOptType andceBindingCore , updatedand! grammar rules and error recovery. |
src/Compiler/SyntaxTree/ParseHelpers.fsi | AddedmkLetExpression andmkAndBang signatures; replaced oldmkLocalBindings . |
src/Compiler/SyntaxTree/ParseHelpers.fs | ImplementedmkLetExpression andmkAndBang , removedmkLocalBindings , unified binding AST creation. |
src/Compiler/Facilities/LanguageFeatures.fsi / .fs | Renamed feature flag toAllowTypedLetUseAndBang and updated version support. |
src/Compiler/Checking/Expressions/CheckComputationExpressions.fs | Updated computation expression checker to use the newAllowTypedLetUseAndBang language feature. |
docs/release-notes/.Language/preview.md | Added entry for preview support ofand! type annotations without parentheses. |
docs/release-notes/.FSharp.Compiler.Service/10.0.100.md | Updated release notes to includeand! 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!)
Uh oh!
There was an error while loading.Please reload this page.
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