@@ -3520,14 +3520,7 @@ bindingPattern:
3520
3520
| headBindingPattern
3521
3521
{ $1, $1.Range }
3522
3522
3523
- /* Common pattern for bindings that may include type annotations
3524
- This rule unifies the pattern parsing for both regular 'let' bindings and
3525
- computation expression bindings (let!, use!, and!).
3526
-
3527
- Returns: (pattern, pattern_range, optional_type)
3528
- - pattern: The parsed pattern (may be typed if annotation present)
3529
- - pattern_range: The full range including any type annotation
3530
- - optional_type: The type if annotation was present, None otherwise */
3523
+ // This rule unifies the pattern parsing for both regular 'let' bindings and (let!, use!, and!)
3531
3524
bindingPatternWithOptType:
3532
3525
| headBindingPattern
3533
3526
{ // Simple pattern without type annotation
@@ -3542,24 +3535,15 @@ bindingPatternWithOptType:
3542
3535
| Some(colonRangeOpt, SynReturnInfo((ty, _), _)) ->
3543
3536
// Pattern with type annotation (e.g., x: int)
3544
3537
let mWhole = unionRanges $1.Range ty.Range
3545
- // Create a typed pattern node
3546
3538
let typedPat = SynPat.Typed($1, ty, mWhole)
3547
3539
typedPat, mWhole, Some ty }
3548
3540
3549
- /* Common rule for computation expression binding patterns
3550
- Handles the pattern part of let!, use!, and! bindings with consistent
3551
- type annotation support and language feature checking.
3552
-
3553
- Returns: (pattern, pattern_range, isInline, isMutable, optional_type) */
3541
+ // Handles the pattern part of let!, use!, and! bindings
3554
3542
ceBindingCore:
3555
3543
| opt_inline opt_mutable bindingPatternWithOptType
3556
3544
{ let pat, mPat, tyOpt = $3
3557
3545
let isInline = Option.isSome $1
3558
3546
let isMutable = Option.isSome $2
3559
-
3560
- // For CE bindings, check language feature if type annotation is present
3561
- // This ensures that typed let!/use!/and! bindings are only allowed when
3562
- // the AllowTypedLetUseAndBang feature is enabled
3563
3547
match tyOpt with
3564
3548
| Some ty ->
3565
3549
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetUseAndBang ty.Range
@@ -4132,9 +4116,7 @@ sequentialExpr:
4132
4116
let usedKeyword = if isUse then "use" else "let"
4133
4117
reportParseErrorAt mLetKwd (FSComp.SR.parsExpectedExpressionAfterLet(usedKeyword, usedKeyword))
4134
4118
let fauxRange = m.EndRange // zero width range at end of m
4135
- // Extract isRec from BindingSetPreAttrs
4136
4119
let isRec = match bindingSet with BindingSetPreAttrs(_, isRec, _, _, _) -> isRec
4137
- // Use mkLetExpression for both let and use expressions
4138
4120
mkLetExpression(false, mLetKwd, mIn, m, arbExpr ("seqExpr", fauxRange), Some(isRec, bindingSet), None) }
4139
4121
4140
4122
/* Use this as the last terminal when performing error recovery */
@@ -4149,12 +4131,8 @@ recover:
4149
4131
{ debugPrint("recovering via EOF"); false }
4150
4132
4151
4133
moreBinders:
4152
- /* Refactored and! bindings to use unified ceBindingCore
4153
- This ensures consistent handling of patterns and type annotations
4154
- across all computation expression bindings */
4155
4134
| AND_BANG ceBindingCore EQUALS typedSequentialExprBlock IN moreBinders %prec expr_let
4156
- { // Handle and! bindings with unified pattern parsing
4157
- let pat, mPat, isInline, isMutable, tyOpt = $2
4135
+ { let pat, mPat, isInline, isMutable, tyOpt = $2
4158
4136
4159
4137
// and! bindings don't support inline or mutable modifiers
4160
4138
if isInline then errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), rhs parseState 2))
@@ -4191,18 +4169,14 @@ declExpr:
4191
4169
{ let mIn = rhs parseState 2 |> Some
4192
4170
let mWhole = unionRanges (rhs2 parseState 1 2) $3.Range
4193
4171
let bindingSet = $1
4194
- // Extract isRec and mKeyword from BindingSetPreAttrs
4195
4172
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4196
- // Use mkLetExpression for both let and use expressions
4197
4173
mkLetExpression(false, mKeyword, mIn, mWhole, $3, Some(isRec, bindingSet), None) }
4198
4174
4199
4175
| defnBindings IN error %prec expr_let
4200
4176
{ let mIn = rhs parseState 2 |> Some
4201
4177
let mWhole = rhs2 parseState 1 2
4202
4178
let bindingSet = $1
4203
- // Extract isRec and mKeyword from BindingSetPreAttrs
4204
4179
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4205
- // Use mkLetExpression for both let and use expressions
4206
4180
mkLetExpression(false, mKeyword, mIn, mWhole, arbExpr ("declExpr1", (rhs parseState 3)), Some(isRec, bindingSet), None) }
4207
4181
/*
4208
4182
FSComp.SR.parsNoMatchingInForLet() -- leave this in for now - it's an unused error string
@@ -4211,34 +4185,26 @@ declExpr:
4211
4185
| hardwhiteLetBindings typedSequentialExprBlock %prec expr_let
4212
4186
{ let bindingSet, m, mIn = $1
4213
4187
let mWhole = unionRanges m $2.Range
4214
- // Extract isRec and mKeyword from BindingSetPreAttrs
4215
4188
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4216
- // Use mkLetExpression for both let and use expressions
4217
4189
mkLetExpression(false, mKeyword, mIn, mWhole, $2, Some(isRec, bindingSet), None) }
4218
4190
4219
4191
| hardwhiteLetBindings error %prec expr_let
4220
4192
{ let bindingSet, m, mIn = $1
4221
4193
reportParseErrorAt (match bindingSet with (BindingSetPreAttrs(m, _, _, _, _)) -> m) (FSComp.SR.parsErrorInReturnForLetIncorrectIndentation())
4222
- // Extract isRec and mKeyword from BindingSetPreAttrs
4223
4194
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4224
- // Use mkLetExpression for both let and use expressions
4225
4195
mkLetExpression(false, mKeyword, mIn, m, arbExpr ("declExpr2", (rhs parseState 2)), Some(isRec, bindingSet), None) }
4226
4196
4227
4197
| hardwhiteLetBindings OBLOCKSEP typedSequentialExprBlock %prec expr_let
4228
4198
{ let bindingSet, m, mIn = $1
4229
4199
let mWhole = unionRanges m $3.Range
4230
- // Extract isRec and mKeyword from BindingSetPreAttrs
4231
4200
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4232
- // Use mkLetExpression for both let and use expressions
4233
4201
mkLetExpression(false, mKeyword, mIn, mWhole, $3, Some(isRec, bindingSet), None) }
4234
4202
4235
4203
| hardwhiteLetBindings OBLOCKSEP error %prec expr_let
4236
4204
{ let bindingSet, m, mIn = $1
4237
4205
//reportParseErrorAt (match bindingSet with (BindingSetPreAttrs(m, _, _, _, _)) -> m) (FSComp.SR.parsErrorInReturnForLetIncorrectIndentation())
4238
4206
let mWhole = unionRanges m (rhs parseState 3)
4239
- // Extract isRec and mKeyword from BindingSetPreAttrs
4240
4207
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4241
- // Use mkLetExpression for both let and use expressions
4242
4208
mkLetExpression(false, mKeyword, mIn, mWhole, arbExpr ("declExpr3", (rhs parseState 3)), Some(isRec, bindingSet), None) }
4243
4209
4244
4210
| hardwhiteDoBinding %prec expr_let
@@ -4562,9 +4528,6 @@ declExpr:
4562
4528
SynExpr.Typed($2, ty, m)
4563
4529
SynExpr.YieldOrReturnFrom(($1, not $1), expr, (unionRanges (rhs parseState 1) $2.Range), trivia) }
4564
4530
4565
- /* Refactored let! and use! bindings to use unified ceBindingCore
4566
- This ensures consistent handling across all computation expression bindings
4567
- while maintaining backward compatibility */
4568
4531
| BINDER ceBindingCore EQUALS typedSequentialExprBlock IN opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let
4569
4532
{ // Handle let! and use! bindings with unified pattern parsing
4570
4533
let pat, mPat, isInline, isMutable, tyOpt = $2
@@ -4580,7 +4543,6 @@ declExpr:
4580
4543
// $1 contains the actual keyword ("let" or "use")
4581
4544
let isUse = ($1 = "use")
4582
4545
4583
- // Use mkLetExpression for both let! and use! bindings
4584
4546
mkLetExpression(true, mKeyword, None, m, $8, None, Some(pat, $4, $7, mEquals, isUse)) }
4585
4547
4586
4548
| OBINDER ceBindingCore EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let
@@ -4599,7 +4561,6 @@ declExpr:
4599
4561
4600
4562
let isUse = ($1 = "use")
4601
4563
4602
- // Use mkLetExpression for both let! and use! bindings
4603
4564
mkLetExpression(true, mKeyword, None, m, $8, None, Some(pat, $4, $7, mEquals, isUse)) }
4604
4565
4605
4566
| OBINDER ceBindingCore EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP error %prec expr_let
@@ -4619,7 +4580,6 @@ declExpr:
4619
4580
let isUse = ($1 = "use")
4620
4581
4621
4582
// Use ImplicitZero as the continuation expression for error recovery
4622
- // Use mkLetExpression for both let! and use! bindings
4623
4583
mkLetExpression(true, mKeyword, None, mAll, SynExpr.ImplicitZero m, None, Some(pat, $4, [], mEquals, isUse)) }
4624
4584
4625
4585
| DO_BANG typedSequentialExpr IN opt_OBLOCKSEP typedSequentialExprBlock %prec expr_let
@@ -6079,6 +6039,7 @@ opt_topReturnTypeWithTypeConstraints:
6079
6039
| COLON recover
6080
6040
{ let mColon = rhs parseState 1
6081
6041
let ty, arity = SynType.FromParseError(mColon.EndRange), SynInfo.unnamedRetVal
6042
+ reportParseErrorAt mColon.EndRange (FSComp.SR.parsExpectingType ())
6082
6043
Some(Some mColon, SynReturnInfo((ty, arity), mColon.EndRange)) }
6083
6044
6084
6045
topType:
0 commit comments