Skip to content

Commit 848fa79

Browse files
committed
wip
1 parent 6edb48b commit 848fa79

File tree

3 files changed

+31
-40
lines changed

3 files changed

+31
-40
lines changed

src/Compiler/SyntaxTree/ParseHelpers.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ let mkClassMemberLocalBindings
868868
SynMemberDefn.LetBindings(decls, isStatic, isRec, mWhole)
869869

870870
/// Creates a SynExprAndBang node for and! bindings in computation expressions
871-
let mkAndBang (mKeyword: range, pat: SynPat, rhs: SynExpr, mWhole: range, mEquals: range, mIn: range option) =
871+
let mkAndBang (mKeyword: range, pat: SynPat, returnInfo: SynBindingReturnInfo option, rhs: SynExpr, mWhole: range, mEquals: range, mIn: range option) =
872872
let spBind = DebugPointAtBinding.Yes(unionRanges mKeyword rhs.Range)
873873

874874
let trivia: SynBindingTrivia =
@@ -887,7 +887,7 @@ let mkAndBang (mKeyword: range, pat: SynPat, rhs: SynExpr, mWhole: range, mEqual
887887
xmlDoc = PreXmlDoc.Empty,
888888
valData = SynInfo.emptySynValData,
889889
headPat = pat,
890-
returnInfo = None,
890+
returnInfo = returnInfo,
891891
expr = rhs,
892892
range = mWhole,
893893
debugPoint = spBind,
@@ -1075,11 +1075,11 @@ let mkLetExpression
10751075
mWhole: range,
10761076
body: SynExpr,
10771077
bindingInfo: BindingSet option,
1078-
bangInfo: (SynPat * SynExpr * SynBinding list * range * range option * bool) option
1078+
bangInfo: (SynPat * SynBindingReturnInfo option * SynExpr * SynBinding list * range * range option * bool) option
10791079
) =
10801080
if isBang then
10811081
match bangInfo with
1082-
| Some(pat, rhs, andBangs, mKeyword, mEquals, isUse) ->
1082+
| Some(pat, returnInfo, rhs, andBangs, mKeyword, mEquals, isUse) ->
10831083
let spBind = DebugPointAtBinding.Yes(unionRanges mKeyword rhs.Range)
10841084

10851085
let trivia: SynBindingTrivia =
@@ -1103,7 +1103,7 @@ let mkLetExpression
11031103
xmlDoc = PreXmlDoc.Empty,
11041104
valData = SynInfo.emptySynValData,
11051105
headPat = pat,
1106-
returnInfo = None,
1106+
returnInfo = returnInfo,
11071107
expr = rhs,
11081108
range = unionRanges mKeyword rhs.Range,
11091109
debugPoint = spBind,

src/Compiler/SyntaxTree/ParseHelpers.fsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ val mkLetExpression:
205205
mWhole: range *
206206
body: SynExpr *
207207
bindingInfo: BindingSet option *
208-
bangInfo: (SynPat * SynExpr * SynBinding list * range * range option * bool) option ->
208+
bangInfo: (SynPat * SynBindingReturnInfo option * SynExpr * SynBinding list * range * range option * bool) option ->
209209
SynExpr
210210

211211
val mkAndBang:
212-
mKeyword: range * pat: SynPat * rhs: SynExpr * mWhole: range * mEquals: range * mIn: range option -> SynBinding
212+
mKeyword: range * pat: SynPat * returnInfo: SynBindingReturnInfo option * rhs: SynExpr * mWhole: range * mEquals: range * mIn: range option -> SynBinding
213213

214214
val mkDefnBindings:
215215
mWhole: range * BindingSet * attrs: SynAttributes * vis: SynAccess option * attrsm: range -> SynModuleDecl list

src/Compiler/pars.fsy

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,32 +3523,23 @@ bindingPattern:
35233523
| headBindingPattern
35243524
{ $1, $1.Range }
35253525

3526-
// This rule unifies the pattern parsing for both regular 'let' bindings and (let!, use!, and!)
3527-
bindingPatternWithOptType:
3528-
| headBindingPattern opt_topReturnTypeWithTypeConstraints
3529-
{ // Pattern with optional type annotation
3530-
match $2 with
3531-
| None ->
3532-
// No type annotation
3533-
$1, $1.Range, None
3534-
| Some(colonRangeOpt, SynReturnInfo((ty, _), _)) ->
3535-
// Pattern with type annotation (e.g., x: int)
3536-
let mWhole = unionRanges $1.Range ty.Range
3537-
let typedPat = SynPat.Typed($1, ty, mWhole)
3538-
typedPat, mWhole, Some ty }
3539-
3540-
// Handles the pattern part of let!, use!, and! bindings
3526+
// Handles pattern and return type part of let!, use!, and! bindings
35413527
ceBindingCore:
3542-
| opt_inline opt_mutable bindingPatternWithOptType
3543-
{ let pat, mPat, tyOpt = $3
3528+
| opt_inline opt_mutable bindingPattern opt_topReturnTypeWithTypeConstraints
3529+
{ let pat, mPat = $3
3530+
let tyOpt = $4
35443531
let isInline = Option.isSome $1
35453532
let isMutable = Option.isSome $2
3546-
match tyOpt with
3547-
| Some ty ->
3548-
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetUseAndBang ty.Range
3549-
| None -> ()
3550-
3551-
pat, mPat, isInline, isMutable, tyOpt }
3533+
3534+
let ty =
3535+
match tyOpt with
3536+
| Some(colonRangeOpt, SynReturnInfo((ty, _), tym)) ->
3537+
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AllowTypedLetUseAndBang ty.Range
3538+
Some (SynBindingReturnInfo(ty, tym, [], { ColonRange = colonRangeOpt }))
3539+
| None ->
3540+
None
3541+
3542+
pat, mPat, isInline, isMutable, ty }
35523543

35533544
opt_simplePatterns:
35543545
| simplePatterns
@@ -4144,7 +4135,7 @@ recover:
41444135

41454136
moreBinders:
41464137
| AND_BANG ceBindingCore EQUALS typedSequentialExprBlock IN moreBinders %prec expr_let
4147-
{ let pat, mPat, isInline, isMutable, tyOpt = $2
4138+
{ let pat, mPat, isInline, isMutable, returnInfo = $2
41484139

41494140
// and! bindings don't support inline or mutable modifiers
41504141
if isInline then errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), rhs parseState 2))
@@ -4155,11 +4146,11 @@ moreBinders:
41554146
let m = unionRanges mKeyword $4.Range
41564147
let mIn = Some(rhs parseState 5)
41574148

4158-
mkAndBang(mKeyword, pat, $4, m, mEquals, mIn) :: $6 }
4149+
mkAndBang(mKeyword, pat, returnInfo, $4, m, mEquals, mIn) :: $6 }
41594150

41604151
| OAND_BANG ceBindingCore EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP moreBinders %prec expr_let
41614152
{ // Offside-sensitive version of and! binding
4162-
let pat, mPat, isInline, isMutable, tyOpt = $2
4153+
let pat, mPat, isInline, isMutable, returnInfo = $2
41634154

41644155
// and! bindings don't support inline or mutable modifiers
41654156
if isInline then errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), rhs parseState 2))
@@ -4171,7 +4162,7 @@ moreBinders:
41714162
let mEquals = rhs parseState 3
41724163
let m = unionRanges mKeyword $4.Range
41734164

4174-
mkAndBang(mKeyword, pat, $4, m, mEquals, mIn) :: $7 }
4165+
mkAndBang(mKeyword, pat, returnInfo, $4, m, mEquals, mIn) :: $7 }
41754166

41764167
| %prec prec_no_more_attr_bindings
41774168
{ [] }
@@ -4536,7 +4527,7 @@ declExpr:
45364527

45374528
| BINDER ceBindingCore EQUALS typedSequentialExprBlock IN opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let
45384529
{ // Handle let! and use! bindings with unified pattern parsing
4539-
let pat, mPat, isInline, isMutable, tyOpt = $2
4530+
let pat, mPat, isInline, isMutable, returnInfo = $2
45404531

45414532
// let! and use! bindings don't support inline or mutable modifiers
45424533
if isInline then errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), rhs parseState 2))
@@ -4549,11 +4540,11 @@ declExpr:
45494540
// $1 contains the actual keyword ("let" or "use")
45504541
let isUse = ($1 = "use")
45514542

4552-
mkLetExpression(true, None, m, $8, None, Some(pat, $4, $7, mKeyword, mEquals, isUse)) }
4543+
mkLetExpression(true, None, m, $8, None, Some(pat, returnInfo, $4, $7, mKeyword, mEquals, isUse)) }
45534544

45544545
| OBINDER ceBindingCore EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP moreBinders typedSequentialExprBlock %prec expr_let
45554546
{ // Offside-sensitive version of let!/use! binding
4556-
let pat, mPat, isInline, isMutable, tyOpt = $2
4547+
let pat, mPat, isInline, isMutable, returnInfo = $2
45574548

45584549
// let! and use! bindings don't support inline or mutable modifiers
45594550
if isInline then errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), rhs parseState 2))
@@ -4567,12 +4558,12 @@ declExpr:
45674558

45684559
let isUse = ($1 = "use")
45694560

4570-
mkLetExpression(true, None, m, $8, None, Some(pat, $4, $7, mKeyword, mEquals, isUse)) }
4561+
mkLetExpression(true, None, m, $8, None, Some(pat, returnInfo, $4, $7, mKeyword, mEquals, isUse)) }
45714562

45724563
| OBINDER ceBindingCore EQUALS typedSequentialExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP error %prec expr_let
45734564
{ // Error recovery for incomplete let!/use! bindings
45744565
// Allows intellisense to work when writing incomplete computation expressions
4575-
let pat, mPat, isInline, isMutable, tyOpt = $2
4566+
let pat, mPat, isInline, isMutable, returnInfo = $2
45764567

45774568
// Error checking for invalid modifiers
45784569
if isInline then errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), rhs parseState 2))
@@ -4586,7 +4577,7 @@ declExpr:
45864577
let isUse = ($1 = "use")
45874578

45884579
// Use ImplicitZero as the continuation expression for error recovery
4589-
mkLetExpression(true, None, mAll, SynExpr.ImplicitZero m, None, Some(pat, $4, [], mKeyword, mEquals, isUse)) }
4580+
mkLetExpression(true, None, mAll, SynExpr.ImplicitZero m, None, Some(pat, returnInfo, $4, [], mKeyword, mEquals, isUse)) }
45904581

45914582
| DO_BANG typedSequentialExpr IN opt_OBLOCKSEP typedSequentialExprBlock %prec expr_let
45924583
{ let spBind = DebugPointAtBinding.NoneAtDo

0 commit comments

Comments
 (0)