Skip to content

Commit fd7e890

Browse files
committed
Use parsExpectingType
1 parent 02fecdf commit fd7e890

19 files changed

+21
-47
lines changed

src/Compiler/SyntaxTree/ParseHelpers.fs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,10 +869,8 @@ let mkClassMemberLocalBindings
869869

870870
/// Creates a SynExprAndBang node for and! bindings in computation expressions
871871
let mkAndBang (mKeyword: range, pat: SynPat, rhs: SynExpr, mWhole: range, mEquals: range, mIn: range option) =
872-
// Calculate debug point range: from keyword through the rhs expression
873872
let spBind = DebugPointAtBinding.Yes(unionRanges mKeyword rhs.Range)
874873

875-
// Create trivia
876874
let trivia: SynExprAndBangTrivia =
877875
{
878876
AndBangKeyword = mKeyword
@@ -1064,9 +1062,7 @@ let mkLetExpression
10641062
mIn: Option<range>,
10651063
mWhole: range,
10661064
body: SynExpr,
1067-
// For regular let/use: binding information
10681065
bindingInfo: (bool * BindingSet) option,
1069-
// For let!/use!: pattern, rhs, andBangs, equals range, and isUse flag
10701066
bangInfo: (SynPat * SynExpr * SynExprAndBang list * range option * bool) option
10711067
) =
10721068
if isBang then

src/Compiler/pars.fsy

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,14 +3520,7 @@ bindingPattern:
35203520
| headBindingPattern
35213521
{ $1, $1.Range }
35223522

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!)
35313524
bindingPatternWithOptType:
35323525
| headBindingPattern
35333526
{ // Simple pattern without type annotation
@@ -3542,24 +3535,15 @@ bindingPatternWithOptType:
35423535
| Some(colonRangeOpt, SynReturnInfo((ty, _), _)) ->
35433536
// Pattern with type annotation (e.g., x: int)
35443537
let mWhole = unionRanges $1.Range ty.Range
3545-
// Create a typed pattern node
35463538
let typedPat = SynPat.Typed($1, ty, mWhole)
35473539
typedPat, mWhole, Some ty }
35483540

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
35543542
ceBindingCore:
35553543
| opt_inline opt_mutable bindingPatternWithOptType
35563544
{ let pat, mPat, tyOpt = $3
35573545
let isInline = Option.isSome $1
35583546
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
35633547
match tyOpt with
35643548
| Some ty ->
35653549
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetUseAndBang ty.Range
@@ -4132,9 +4116,7 @@ sequentialExpr:
41324116
let usedKeyword = if isUse then "use" else "let"
41334117
reportParseErrorAt mLetKwd (FSComp.SR.parsExpectedExpressionAfterLet(usedKeyword, usedKeyword))
41344118
let fauxRange = m.EndRange // zero width range at end of m
4135-
// Extract isRec from BindingSetPreAttrs
41364119
let isRec = match bindingSet with BindingSetPreAttrs(_, isRec, _, _, _) -> isRec
4137-
// Use mkLetExpression for both let and use expressions
41384120
mkLetExpression(false, mLetKwd, mIn, m, arbExpr ("seqExpr", fauxRange), Some(isRec, bindingSet), None) }
41394121

41404122
/* Use this as the last terminal when performing error recovery */
@@ -4149,12 +4131,8 @@ recover:
41494131
{ debugPrint("recovering via EOF"); false }
41504132

41514133
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 */
41554134
| 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
41584136

41594137
// and! bindings don't support inline or mutable modifiers
41604138
if isInline then errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), rhs parseState 2))
@@ -4191,18 +4169,14 @@ declExpr:
41914169
{ let mIn = rhs parseState 2 |> Some
41924170
let mWhole = unionRanges (rhs2 parseState 1 2) $3.Range
41934171
let bindingSet = $1
4194-
// Extract isRec and mKeyword from BindingSetPreAttrs
41954172
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4196-
// Use mkLetExpression for both let and use expressions
41974173
mkLetExpression(false, mKeyword, mIn, mWhole, $3, Some(isRec, bindingSet), None) }
41984174

41994175
| defnBindings IN error %prec expr_let
42004176
{ let mIn = rhs parseState 2 |> Some
42014177
let mWhole = rhs2 parseState 1 2
42024178
let bindingSet = $1
4203-
// Extract isRec and mKeyword from BindingSetPreAttrs
42044179
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4205-
// Use mkLetExpression for both let and use expressions
42064180
mkLetExpression(false, mKeyword, mIn, mWhole, arbExpr ("declExpr1", (rhs parseState 3)), Some(isRec, bindingSet), None) }
42074181
/*
42084182
FSComp.SR.parsNoMatchingInForLet() -- leave this in for now - it's an unused error string
@@ -4211,34 +4185,26 @@ declExpr:
42114185
| hardwhiteLetBindings typedSequentialExprBlock %prec expr_let
42124186
{ let bindingSet, m, mIn = $1
42134187
let mWhole = unionRanges m $2.Range
4214-
// Extract isRec and mKeyword from BindingSetPreAttrs
42154188
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4216-
// Use mkLetExpression for both let and use expressions
42174189
mkLetExpression(false, mKeyword, mIn, mWhole, $2, Some(isRec, bindingSet), None) }
42184190

42194191
| hardwhiteLetBindings error %prec expr_let
42204192
{ let bindingSet, m, mIn = $1
42214193
reportParseErrorAt (match bindingSet with (BindingSetPreAttrs(m, _, _, _, _)) -> m) (FSComp.SR.parsErrorInReturnForLetIncorrectIndentation())
4222-
// Extract isRec and mKeyword from BindingSetPreAttrs
42234194
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4224-
// Use mkLetExpression for both let and use expressions
42254195
mkLetExpression(false, mKeyword, mIn, m, arbExpr ("declExpr2", (rhs parseState 2)), Some(isRec, bindingSet), None) }
42264196

42274197
| hardwhiteLetBindings OBLOCKSEP typedSequentialExprBlock %prec expr_let
42284198
{ let bindingSet, m, mIn = $1
42294199
let mWhole = unionRanges m $3.Range
4230-
// Extract isRec and mKeyword from BindingSetPreAttrs
42314200
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4232-
// Use mkLetExpression for both let and use expressions
42334201
mkLetExpression(false, mKeyword, mIn, mWhole, $3, Some(isRec, bindingSet), None) }
42344202

42354203
| hardwhiteLetBindings OBLOCKSEP error %prec expr_let
42364204
{ let bindingSet, m, mIn = $1
42374205
//reportParseErrorAt (match bindingSet with (BindingSetPreAttrs(m, _, _, _, _)) -> m) (FSComp.SR.parsErrorInReturnForLetIncorrectIndentation())
42384206
let mWhole = unionRanges m (rhs parseState 3)
4239-
// Extract isRec and mKeyword from BindingSetPreAttrs
42404207
let mKeyword, isRec = match bindingSet with BindingSetPreAttrs(m, isRec, _, _, _) -> m, isRec
4241-
// Use mkLetExpression for both let and use expressions
42424208
mkLetExpression(false, mKeyword, mIn, mWhole, arbExpr ("declExpr3", (rhs parseState 3)), Some(isRec, bindingSet), None) }
42434209

42444210
| hardwhiteDoBinding %prec expr_let
@@ -4562,9 +4528,6 @@ declExpr:
45624528
SynExpr.Typed($2, ty, m)
45634529
SynExpr.YieldOrReturnFrom(($1, not $1), expr, (unionRanges (rhs parseState 1) $2.Range), trivia) }
45644530

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 */
45684531
| BINDER ceBindingCore EQUALS typedSequentialExprBlock IN opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let
45694532
{ // Handle let! and use! bindings with unified pattern parsing
45704533
let pat, mPat, isInline, isMutable, tyOpt = $2
@@ -4580,7 +4543,6 @@ declExpr:
45804543
// $1 contains the actual keyword ("let" or "use")
45814544
let isUse = ($1 = "use")
45824545

4583-
// Use mkLetExpression for both let! and use! bindings
45844546
mkLetExpression(true, mKeyword, None, m, $8, None, Some(pat, $4, $7, mEquals, isUse)) }
45854547

45864548
| OBINDER ceBindingCore EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let
@@ -4599,7 +4561,6 @@ declExpr:
45994561

46004562
let isUse = ($1 = "use")
46014563

4602-
// Use mkLetExpression for both let! and use! bindings
46034564
mkLetExpression(true, mKeyword, None, m, $8, None, Some(pat, $4, $7, mEquals, isUse)) }
46044565

46054566
| OBINDER ceBindingCore EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP error %prec expr_let
@@ -4619,7 +4580,6 @@ declExpr:
46194580
let isUse = ($1 = "use")
46204581

46214582
// Use ImplicitZero as the continuation expression for error recovery
4622-
// Use mkLetExpression for both let! and use! bindings
46234583
mkLetExpression(true, mKeyword, None, mAll, SynExpr.ImplicitZero m, None, Some(pat, $4, [], mEquals, isUse)) }
46244584

46254585
| DO_BANG typedSequentialExpr IN opt_OBLOCKSEP typedSequentialExprBlock %prec expr_let
@@ -6079,6 +6039,7 @@ opt_topReturnTypeWithTypeConstraints:
60796039
| COLON recover
60806040
{ let mColon = rhs parseState 1
60816041
let ty, arity = SynType.FromParseError(mColon.EndRange), SynInfo.unnamedRetVal
6042+
reportParseErrorAt mColon.EndRange (FSComp.SR.parsExpectingType ())
60826043
Some(Some mColon, SynReturnInfo((ty, arity), mColon.EndRange)) }
60836044

60846045
topType:

tests/service/data/SyntaxTree/Expression/Return 07.fs.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ ImplFile
3535
CodeComments = [] }, set []))
3636

3737
(6,4)-(6,5) parse error Unexpected symbol '}' in expression
38+
(5,29)-(5,29) parse error Expecting type

tests/service/data/SyntaxTree/Expression/ReturnBang 03.fs.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ ImplFile
3636
CodeComments = [] }, set []))
3737

3838
(6,4)-(6,5) parse error Unexpected symbol '}' in expression
39+
(5,30)-(5,30) parse error Expecting type

tests/service/data/SyntaxTree/Expression/Yield 05.fs.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ ImplFile
2929
CodeComments = [] }, set []))
3030

3131
(5,0)-(5,1) parse error Unexpected symbol '}' in expression
32+
(4,23)-(4,23) parse error Expecting type

tests/service/data/SyntaxTree/Expression/Yield 06.fs.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ ImplFile
2929
CodeComments = [] }, set []))
3030

3131
(5,0)-(5,1) parse error Unexpected symbol '}' in expression
32+
(4,23)-(4,23) parse error Expecting type

tests/service/data/SyntaxTree/Expression/YieldBang 05.fs.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ ImplFile
2929
CodeComments = [] }, set []))
3030

3131
(5,0)-(5,1) parse error Unexpected symbol '}' in expression
32+
(4,24)-(4,24) parse error Expecting type

tests/service/data/SyntaxTree/Expression/YieldBang 06.fs.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ ImplFile
2222
CodeComments = [] }, set []))
2323

2424
(5,0)-(5,0) parse error Incomplete structured construct at or before this point in expression
25+
(3,20)-(3,20) parse error Expecting type

tests/service/data/SyntaxTree/Member/Member 13.fs.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ ImplFile
7575
CodeComments = [] }, set []))
7676

7777
(6,0)-(6,4) parse error Incomplete structured construct at or before this point in member definition
78+
(4,20)-(4,20) parse error Expecting type
7879
(6,0)-(6,4) parse error Expecting member body

tests/service/data/SyntaxTree/Pattern/Typed - Missing type 01.fs.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ ImplFile
2929
CodeComments = [] }, set []))
3030

3131
(5,0)-(5,1) parse error Incomplete structured construct at or before this point in binding
32+
(3,6)-(3,6) parse error Expecting type
3233
(6,0)-(6,0) parse error Unexpected end of input in value, function or member definition
3334
(3,0)-(3,3) parse error Incomplete value or function definition. If this is in an expression, the body of the expression must be indented to the same column as the 'let' keyword.

0 commit comments

Comments
 (0)