Skip to content

Commit b66de35

Browse files
authored
Parser: recover on missing types in typed-like expressions (#15054)
1 parent 4e8a29a commit b66de35

33 files changed

+321
-4
lines changed

src/Compiler/pars.fsy

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,9 +3458,14 @@ typedSequentialExprBlockR:
34583458
| recover
34593459
{ fun mStart -> arbExpr ("typedSequentialExprBlockR", mStart) }
34603460

3461-
typedSequentialExpr:
3461+
typedSequentialExpr:
34623462
| sequentialExpr COLON typeWithTypeConstraints
3463-
{ SynExpr.Typed ($1, $3, unionRanges $1.Range $3.Range) }
3463+
{ SynExpr.Typed ($1, $3, unionRanges $1.Range $3.Range) }
3464+
3465+
| sequentialExpr COLON recover
3466+
{ let mColon = rhs parseState 2
3467+
let ty = SynType.FromParseError(mColon.EndRange)
3468+
SynExpr.Typed ($1, ty, unionRanges $1.Range mColon) }
34643469

34653470
| sequentialExpr
34663471
{ $1 }
@@ -3889,14 +3894,29 @@ declExpr:
38893894
SynExpr.YieldOrReturn ((true, true), expr, (unionRanges mArrow expr.Range)) }
38903895

38913896
| declExpr COLON_QMARK typ
3892-
{ SynExpr.TypeTest ($1, $3, unionRanges $1.Range $3.Range) }
3897+
{ SynExpr.TypeTest($1, $3, unionRanges $1.Range $3.Range) }
3898+
3899+
| declExpr COLON_QMARK recover
3900+
{ let mColon = rhs parseState 2
3901+
let ty = SynType.FromParseError(mColon.EndRange)
3902+
SynExpr.TypeTest($1, ty, unionRanges $1.Range mColon) }
38933903

38943904
| declExpr COLON_GREATER typ
3895-
{ SynExpr.Upcast ($1, $3, unionRanges $1.Range $3.Range) }
3905+
{ SynExpr.Upcast($1, $3, unionRanges $1.Range $3.Range) }
3906+
3907+
| declExpr COLON_GREATER recover
3908+
{ let mOp = rhs parseState 2
3909+
let ty = SynType.FromParseError(mOp.EndRange)
3910+
SynExpr.Upcast($1, ty, unionRanges $1.Range mOp) }
38963911

38973912
| declExpr COLON_QMARK_GREATER typ
38983913
{ SynExpr.Downcast ($1, $3, unionRanges $1.Range $3.Range) }
38993914

3915+
| declExpr COLON_QMARK_GREATER recover
3916+
{ let mOp = rhs parseState 2
3917+
let ty = SynType.FromParseError(mOp.EndRange)
3918+
SynExpr.Downcast($1, ty, unionRanges $1.Range mOp) }
3919+
39003920
| declExpr COLON_EQUALS declExpr
39013921
{ mkSynInfix (rhs parseState 2) $1 ":=" $3 }
39023922

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Module
2+
3+
i :?>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/Expression/Downcast 01.fs", false, QualifiedNameOfFile Module, [],
4+
[],
5+
[SynModuleOrNamespace
6+
([Module], false, NamedModule,
7+
[Expr
8+
(Downcast (Ident i, FromParseError (3,5--3,5), (3,0--3,5)),
9+
(3,0--3,5))],
10+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
11+
(1,0--3,5), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
12+
{ ConditionalDirectives = []
13+
CodeComments = [] }, set []))
14+
15+
(4,0)-(4,0) parse warning Possible incorrect indentation: this token is offside of context started at position (3:1). Try indenting this token further or using standard formatting conventions.
16+
(4,0)-(4,0) parse error Incomplete structured construct at or before this point in expression
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Module
2+
3+
i :?>
4+
()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/Expression/Downcast 02.fs", false, QualifiedNameOfFile Module, [],
4+
[],
5+
[SynModuleOrNamespace
6+
([Module], false, NamedModule,
7+
[Expr (Downcast (Ident i, Anon (4,0--4,2), (3,0--4,2)), (3,0--4,2))],
8+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
9+
(1,0--4,2), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
10+
{ ConditionalDirectives = []
11+
CodeComments = [] }, set []))
12+
13+
(4,1)-(4,2) parse error Unexpected symbol ')' in expression
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Module
2+
3+
i :?>
4+
i
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/Expression/Downcast 03.fs", false, QualifiedNameOfFile Module, [],
4+
[],
5+
[SynModuleOrNamespace
6+
([Module], false, NamedModule,
7+
[Expr
8+
(Downcast
9+
(Ident i, LongIdent (SynLongIdent ([i], [], [None])), (3,0--4,1)),
10+
(3,0--4,1))],
11+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
12+
(1,0--4,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
13+
{ ConditionalDirectives = []
14+
CodeComments = [] }, set []))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Module
2+
3+
i :?
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/Expression/Type test 01.fs", false, QualifiedNameOfFile Module, [],
4+
[],
5+
[SynModuleOrNamespace
6+
([Module], false, NamedModule,
7+
[Expr
8+
(TypeTest (Ident i, FromParseError (3,4--3,4), (3,0--3,4)),
9+
(3,0--3,4))],
10+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
11+
(1,0--3,4), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
12+
{ ConditionalDirectives = []
13+
CodeComments = [] }, set []))
14+
15+
(4,0)-(4,0) parse error Incomplete structured construct at or before this point in expression
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Module
2+
3+
i :?
4+
()

0 commit comments

Comments
 (0)