Skip to content

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

Merged
merged 58 commits into from
Jul 29, 2025

Conversation

edgarfgp
Copy link
Contributor

@edgarfgp edgarfgp commented Jun 10, 2025

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:

  • New parsing rules: bindingPatternWithOptType and ceBindingCore
  • New helper functions: mkLetExpression and mkAndBang
  • Renamed language feature to 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) to LetOrUse.

type SynExpr =
    | LetOrUse of 
        isRecursive: bool * 
        isUse: bool * 
        isComputed: bool *     // NEW: true for let!/use!, false for let/use
        bindings: SynBinding list * 
        body: SynExpr * 
        range: range * 
        trivia: SynExprLetOrUseTrivia

Checklist

  • Test cases added
  • Release notes entry updated

@edgarfgp edgarfgp changed the title Allow and bang typed bindings Allow and! typed bindings Jun 10, 2025
Copy link
Contributor

github-actions bot commented Jun 10, 2025

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
LanguageFeatures.fsi docs/release-notes/.Language/preview.md

@edgarfgp edgarfgp changed the title Allow and! typed bindings Allow typed bindings(and!) in CE without parentheses Jun 10, 2025
Copy link

@Copilot Copilot AI left a 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!)

@edgarfgp edgarfgp marked this pull request as ready for review July 15, 2025 03:02
@edgarfgp edgarfgp requested a review from a team as a code owner July 15, 2025 03:02
@edgarfgp edgarfgp requested review from T-Gro and auduchinok July 15, 2025 03:03
@edgarfgp edgarfgp closed this Jul 23, 2025
@edgarfgp edgarfgp reopened this Jul 23, 2025
@edgarfgp edgarfgp requested a review from T-Gro July 23, 2025 03:31
@edgarfgp
Copy link
Contributor Author

This is ready @T-Gro

@T-Gro
Copy link
Member

T-Gro commented Jul 29, 2025

Thanks @edgarfgp for getting this in.
The resulting parser code is more unified and better readable across the similar syntactical constructs 👍 .

@edgarfgp
Copy link
Contributor Author

/azn run

@edgarfgp
Copy link
Contributor Author

Thanks @T-Gro. Can you please re-run the CI ?. Don't want to close a re-open the PR.

@T-Gro
Copy link
Member

T-Gro commented Jul 29, 2025

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@T-Gro T-Gro enabled auto-merge (squash) July 29, 2025 10:43
@T-Gro T-Gro merged commit e7abd44 into dotnet:main Jul 29, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants