Skip to content

Commit 7bfec2c

Browse files
committed
Parser: fix recovery for unfinished match clause
Fixes recovery for missing right hand sides: ``` match () with | x ```
1 parent 985b85c commit 7bfec2c

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/fsharp/pars.fsy

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ let debugPrint s = ignore s
3636

3737
let exprFromParseError (e:SynExpr) = SynExpr.FromParseError (e, e.Range)
3838

39+
let unitExprFromRange m = SynExpr.Const (SynConst.Unit, m)
40+
let unitExprFromParseError m = unitExprFromRange m |> exprFromParseError
41+
3942
let patFromParseError (e:SynPat) = SynPat.FromParseError(e, e.Range)
4043

4144
// record bindings returned by the recdExprBindings rule has shape:
@@ -2337,13 +2340,6 @@ opt_explicitValTyparDecls:
23372340
|
23382341
{ SynValTyparDecls(None, true) }
23392342

2340-
opt_explicitValTyparDecls2:
2341-
| explicitValTyparDecls
2342-
{ Some $1 }
2343-
2344-
| /* EMPTY */
2345-
{ None }
2346-
23472343
/* Any tokens in this grammar must be added to the lex filter rule 'peekAdjacentTypars' */
23482344
/* See the F# specification "Lexical analysis of type applications and type parameter definitions" */
23492345
opt_typeConstraints:
@@ -3103,17 +3099,26 @@ namePatPair:
31033099
{ ($1, $3) }
31043100

31053101
constrPattern:
3106-
| atomicPatternLongIdent explicitValTyparDecls
3102+
| atomicPatternLongIdent explicitValTyparDecls
31073103
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, Some $2, SynArgPats.Pats [], vis, lhs parseState) }
31083104

3109-
| atomicPatternLongIdent opt_explicitValTyparDecls2 atomicPatsOrNamePatPairs %prec pat_app
3110-
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, $2, $3, vis, lhs parseState) }
3105+
| atomicPatternLongIdent explicitValTyparDecls atomicPatsOrNamePatPairs %prec pat_app
3106+
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, Some $2, $3, vis, lhs parseState) }
3107+
3108+
| atomicPatternLongIdent explicitValTyparDecls HIGH_PRECEDENCE_PAREN_APP atomicPatsOrNamePatPairs
3109+
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, Some $2, $4, vis, lhs parseState) }
3110+
3111+
| atomicPatternLongIdent explicitValTyparDecls HIGH_PRECEDENCE_BRACK_APP atomicPatsOrNamePatPairs
3112+
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, Some $2, $4, vis, lhs parseState) }
3113+
3114+
| atomicPatternLongIdent atomicPatsOrNamePatPairs %prec pat_app
3115+
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, None, $2, vis, lhs parseState) }
31113116

3112-
| atomicPatternLongIdent opt_explicitValTyparDecls2 HIGH_PRECEDENCE_PAREN_APP atomicPatsOrNamePatPairs
3113-
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, $2, $4, vis, lhs parseState) }
3117+
| atomicPatternLongIdent HIGH_PRECEDENCE_PAREN_APP atomicPatsOrNamePatPairs
3118+
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, None, $3, vis, lhs parseState) }
31143119

3115-
| atomicPatternLongIdent opt_explicitValTyparDecls2 HIGH_PRECEDENCE_BRACK_APP atomicPatsOrNamePatPairs
3116-
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, $2, $4, vis, lhs parseState) }
3120+
| atomicPatternLongIdent HIGH_PRECEDENCE_BRACK_APP atomicPatsOrNamePatPairs
3121+
{ let vis, lid = $1 in SynPat.LongIdent (lid, None, None, $3, vis, lhs parseState) }
31173122

31183123
| COLON_QMARK atomTypeOrAnonRecdType %prec pat_isinst
31193124
{ SynPat.IsInst($2, lhs parseState) }
@@ -3994,7 +3999,7 @@ patternClauses:
39943999
| Some e -> unionRanges patm e.Range
39954000
| _ -> patm
39964001
// silent recovery
3997-
[SynMatchClause(pat, guard, None, SynExpr.Const (SynConst.Unit, mLast.EndRange), m, DebugPointAtTarget.Yes)], mLast }
4002+
[SynMatchClause(pat, guard, None, unitExprFromParseError mLast.EndRange, m, DebugPointAtTarget.Yes)], mLast }
39984003

39994004
patternGuard:
40004005
| WHEN declExpr

0 commit comments

Comments
 (0)