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

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

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
Member

@auduchinok auduchinok left a 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.

@github-project-automation github-project-automation bot moved this from New to In Progress in F# Compiler and Tooling Jun 18, 2025
@edgarfgp edgarfgp force-pushed the allow-and-bang-typed-bindings branch from 11a44ca to 2e074f0 Compare June 19, 2025 14:22
@edgarfgp edgarfgp force-pushed the allow-and-bang-typed-bindings branch from 2e074f0 to c03a338 Compare June 19, 2025 19:07
@edgarfgp edgarfgp force-pushed the allow-and-bang-typed-bindings branch from fdd8074 to 9e50380 Compare July 6, 2025 16:22
@edgarfgp
Copy link
Contributor Author

/azp run

Copy link

Commenter does not have sufficient privileges for PR 18682 in repo dotnet/fsharp

@edgarfgp edgarfgp force-pushed the allow-and-bang-typed-bindings branch from 009b91b to 02fecdf Compare July 12, 2025 20:12
@edgarfgp edgarfgp force-pushed the allow-and-bang-typed-bindings branch from 34ec912 to fd7e890 Compare July 12, 2025 21:19
@edgarfgp edgarfgp requested a review from Copilot July 15, 2025 01:45
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants