Skip to content

Commit 174a20a

Browse files
committed
Parser: recover on missing types in typed expressions
1 parent 7670781 commit 174a20a

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
@@ -3448,9 +3448,14 @@ typedSequentialExprBlockR:
34483448
| recover
34493449
{ fun mStart -> arbExpr ("typedSequentialExprBlockR", mStart) }
34503450

3451-
typedSequentialExpr:
3451+
typedSequentialExpr:
34523452
| sequentialExpr COLON typeWithTypeConstraints
3453-
{ SynExpr.Typed ($1, $3, unionRanges $1.Range $3.Range) }
3453+
{ SynExpr.Typed ($1, $3, unionRanges $1.Range $3.Range) }
3454+
3455+
| sequentialExpr COLON recover
3456+
{ let mColon = rhs parseState 2
3457+
let ty = SynType.FromParseError(mColon.EndRange)
3458+
SynExpr.Typed ($1, ty, unionRanges $1.Range mColon) }
34543459

34553460
| sequentialExpr
34563461
{ $1 }
@@ -3879,14 +3884,29 @@ declExpr:
38793884
SynExpr.YieldOrReturn ((true, true), expr, (unionRanges mArrow expr.Range)) }
38803885

38813886
| declExpr COLON_QMARK typ
3882-
{ SynExpr.TypeTest ($1, $3, unionRanges $1.Range $3.Range) }
3887+
{ SynExpr.TypeTest($1, $3, unionRanges $1.Range $3.Range) }
3888+
3889+
| declExpr COLON_QMARK recover
3890+
{ let mColon = rhs parseState 2
3891+
let ty = SynType.FromParseError(mColon.EndRange)
3892+
SynExpr.TypeTest($1, ty, unionRanges $1.Range mColon) }
38833893

38843894
| declExpr COLON_GREATER typ
3885-
{ SynExpr.Upcast ($1, $3, unionRanges $1.Range $3.Range) }
3895+
{ SynExpr.Upcast($1, $3, unionRanges $1.Range $3.Range) }
3896+
3897+
| declExpr COLON_GREATER recover
3898+
{ let mOp = rhs parseState 2
3899+
let ty = SynType.FromParseError(mOp.EndRange)
3900+
SynExpr.Upcast($1, ty, unionRanges $1.Range mOp) }
38863901

38873902
| declExpr COLON_QMARK_GREATER typ
38883903
{ SynExpr.Downcast ($1, $3, unionRanges $1.Range $3.Range) }
38893904

3905+
| declExpr COLON_QMARK_GREATER recover
3906+
{ let mOp = rhs parseState 2
3907+
let ty = SynType.FromParseError(mOp.EndRange)
3908+
SynExpr.Downcast($1, ty, unionRanges $1.Range mOp) }
3909+
38903910
| declExpr COLON_EQUALS declExpr
38913911
{ mkSynInfix (rhs parseState 2) $1 ":=" $3 }
38923912

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)