Skip to content

Commit 009b91b

Browse files
committed
cover error cases in the grammar
1 parent cc89f66 commit 009b91b

13 files changed

+296
-16
lines changed

src/Compiler/pars.fsy

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,22 +3533,18 @@ bindingPatternWithOptType:
35333533
{ // Simple pattern without type annotation
35343534
$1, $1.Range, None }
35353535

3536-
| headBindingPattern COLON topTypeWithTypeConstraints
3537-
{ // Pattern with type annotation (e.g., x: int)
3538-
let ty, arity = $3
3539-
let mWhole = unionRanges $1.Range ty.Range
3540-
// Create a typed pattern node
3541-
let typedPat = SynPat.Typed($1, ty, mWhole)
3542-
typedPat, mWhole, Some ty }
3543-
3544-
| headBindingPattern COLON error
3545-
{ // Error recovery: incomplete type annotation (e.g., "let x:" with no type)
3546-
let mColon = rhs parseState 2
3547-
let mWhole = unionRanges $1.Range mColon
3548-
// Create a typed pattern with an error type for recovery
3549-
let errorType = SynType.FromParseError(mColon.EndRange)
3550-
let typedPat = SynPat.Typed($1, errorType, mWhole)
3551-
typedPat, mWhole, Some errorType }
3536+
| headBindingPattern opt_topReturnTypeWithTypeConstraints
3537+
{ // Pattern with optional type annotation
3538+
match $2 with
3539+
| None ->
3540+
// No type annotation
3541+
$1, $1.Range, None
3542+
| Some(colonRangeOpt, SynReturnInfo((ty, _), _)) ->
3543+
// Pattern with type annotation (e.g., x: int)
3544+
let mWhole = unionRanges $1.Range ty.Range
3545+
// Create a typed pattern node
3546+
let typedPat = SynPat.Typed($1, ty, mWhole)
3547+
typedPat, mWhole, Some ty }
35523548

35533549
/* Common rule for computation expression binding patterns
35543550
Handles the pattern part of let!, use!, and! bindings with consistent
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Module
2+
3+
async {
4+
let! (x as y): = asyncInt()
5+
and! (a as b): string = asyncString()
6+
return x + b
7+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/SynType/Typed LetBang 14.fs", false, QualifiedNameOfFile Module, [],
4+
[SynModuleOrNamespace
5+
([Module], false, NamedModule,
6+
[Expr
7+
(App
8+
(NonAtomic, false, Ident async,
9+
ComputationExpr
10+
(false,
11+
LetOrUseBang
12+
(Yes (4,4--4,31), false, true,
13+
Typed
14+
(Paren
15+
(As
16+
(Named
17+
(SynIdent (x, None), false, None, (4,10--4,11)),
18+
Named
19+
(SynIdent (y, None), false, None, (4,15--4,16)),
20+
(4,10--4,16)), (4,9--4,17)),
21+
FromParseError (4,18--4,18), (4,9--4,18)),
22+
App
23+
(Atomic, false, Ident asyncInt,
24+
Const (Unit, (4,29--4,31)), (4,21--4,31)),
25+
[SynExprAndBang
26+
(Yes (5,4--5,41), false, true,
27+
Typed
28+
(Paren
29+
(As
30+
(Named
31+
(SynIdent (a, None), false, None,
32+
(5,10--5,11)),
33+
Named
34+
(SynIdent (b, None), false, None,
35+
(5,15--5,16)), (5,10--5,16)), (5,9--5,17)),
36+
LongIdent (SynLongIdent ([string], [], [None])),
37+
(5,9--5,25)),
38+
App
39+
(Atomic, false, Ident asyncString,
40+
Const (Unit, (5,39--5,41)), (5,28--5,41)),
41+
(5,4--5,41), { AndBangKeyword = (5,4--5,8)
42+
EqualsRange = (5,26--5,27)
43+
InKeyword = None })],
44+
YieldOrReturn
45+
((false, true),
46+
App
47+
(NonAtomic, false,
48+
App
49+
(NonAtomic, true,
50+
LongIdent
51+
(false,
52+
SynLongIdent
53+
([op_Addition], [],
54+
[Some (OriginalNotation "+")]), None,
55+
(6,13--6,14)), Ident x, (6,11--6,14)),
56+
Ident b, (6,11--6,16)), (6,4--6,16),
57+
{ YieldOrReturnKeyword = (6,4--6,10) }), (4,4--6,16),
58+
{ LetOrUseBangKeyword = (4,4--4,8)
59+
EqualsRange = Some (4,19--4,20) }), (3,6--7,1)),
60+
(3,0--7,1)), (3,0--7,1))],
61+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
62+
(1,0--7,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
63+
{ ConditionalDirectives = []
64+
WarnDirectives = []
65+
CodeComments = [] }, set []))
66+
67+
(4,19)-(4,20) parse error Unexpected symbol '=' in expression
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Module
2+
3+
async {
4+
let! (x as y):
5+
and! (a as b): string = asyncString()
6+
return x + b
7+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/SynType/Typed LetBang 15.fs", false, QualifiedNameOfFile Module, [],
4+
[SynModuleOrNamespace
5+
([Module], false, NamedModule,
6+
[Expr
7+
(App
8+
(NonAtomic, false, Ident async,
9+
ComputationExpr
10+
(false,
11+
LetOrUseBang
12+
(Yes (4,4--5,41), false, true,
13+
Typed
14+
(Paren
15+
(As
16+
(Named
17+
(SynIdent (x, None), false, None, (4,10--4,11)),
18+
Named
19+
(SynIdent (y, None), false, None, (4,15--4,16)),
20+
(4,10--4,16)), (4,9--4,17)),
21+
FromParseError (4,18--4,18), (4,9--4,18)),
22+
App
23+
(Atomic, false, Ident asyncString,
24+
Const (Unit, (5,39--5,41)), (5,28--5,41)), [],
25+
YieldOrReturn
26+
((false, true),
27+
App
28+
(NonAtomic, false,
29+
App
30+
(NonAtomic, true,
31+
LongIdent
32+
(false,
33+
SynLongIdent
34+
([op_Addition], [],
35+
[Some (OriginalNotation "+")]), None,
36+
(6,13--6,14)), Ident x, (6,11--6,14)),
37+
Ident b, (6,11--6,16)), (6,4--6,16),
38+
{ YieldOrReturnKeyword = (6,4--6,10) }), (4,4--6,16),
39+
{ LetOrUseBangKeyword = (4,4--4,8)
40+
EqualsRange = Some (5,26--5,27) }), (3,6--7,1)),
41+
(3,0--7,1)), (3,0--7,1))],
42+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
43+
(1,0--7,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
44+
{ ConditionalDirectives = []
45+
WarnDirectives = []
46+
CodeComments = [] }, set []))
47+
48+
(5,4)-(5,8) parse error Incomplete structured construct at or before this point in expression
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Module
2+
3+
async {
4+
let! (x as y): int = asyncInt()
5+
and! (a as b):
6+
return x + b
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/SynType/Typed LetBang 16.fs", false,
4+
QualifiedNameOfFile Typed LetBang 16, [],
5+
[SynModuleOrNamespace
6+
([Typed LetBang 16], false, AnonModule, [], PreXmlDocEmpty, [], None,
7+
(7,1--7,1), { LeadingKeyword = None })], (true, true),
8+
{ ConditionalDirectives = []
9+
WarnDirectives = []
10+
CodeComments = [] }, set []))
11+
12+
(6,4)-(6,10) parse error Incomplete structured construct at or before this point in expression
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Module
2+
3+
async {
4+
let! (x as y): int = asyncInt()
5+
and! (a as b): = asyncString()
6+
return x + b
7+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/SynType/Typed LetBang AndBang 18.fs", false,
4+
QualifiedNameOfFile Module, [],
5+
[SynModuleOrNamespace
6+
([Module], false, NamedModule,
7+
[Expr
8+
(App
9+
(NonAtomic, false, Ident async,
10+
ComputationExpr
11+
(false,
12+
LetOrUseBang
13+
(Yes (4,4--4,35), false, true,
14+
Typed
15+
(Paren
16+
(As
17+
(Named
18+
(SynIdent (x, None), false, None, (4,10--4,11)),
19+
Named
20+
(SynIdent (y, None), false, None, (4,15--4,16)),
21+
(4,10--4,16)), (4,9--4,17)),
22+
LongIdent (SynLongIdent ([int], [], [None])),
23+
(4,9--4,22)),
24+
App
25+
(Atomic, false, Ident asyncInt,
26+
Const (Unit, (4,33--4,35)), (4,25--4,35)),
27+
[SynExprAndBang
28+
(Yes (5,4--5,34), false, true,
29+
Typed
30+
(Paren
31+
(As
32+
(Named
33+
(SynIdent (a, None), false, None,
34+
(5,10--5,11)),
35+
Named
36+
(SynIdent (b, None), false, None,
37+
(5,15--5,16)), (5,10--5,16)), (5,9--5,17)),
38+
FromParseError (5,18--5,18), (5,9--5,18)),
39+
App
40+
(Atomic, false, Ident asyncString,
41+
Const (Unit, (5,32--5,34)), (5,21--5,34)),
42+
(5,4--5,34), { AndBangKeyword = (5,4--5,8)
43+
EqualsRange = (5,19--5,20)
44+
InKeyword = None })],
45+
YieldOrReturn
46+
((false, true),
47+
App
48+
(NonAtomic, false,
49+
App
50+
(NonAtomic, true,
51+
LongIdent
52+
(false,
53+
SynLongIdent
54+
([op_Addition], [],
55+
[Some (OriginalNotation "+")]), None,
56+
(6,13--6,14)), Ident x, (6,11--6,14)),
57+
Ident b, (6,11--6,16)), (6,4--6,16),
58+
{ YieldOrReturnKeyword = (6,4--6,10) }), (4,4--6,16),
59+
{ LetOrUseBangKeyword = (4,4--4,8)
60+
EqualsRange = Some (4,23--4,24) }), (3,6--7,1)),
61+
(3,0--7,1)), (3,0--7,1))],
62+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
63+
(1,0--7,1), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
64+
{ ConditionalDirectives = []
65+
WarnDirectives = []
66+
CodeComments = [] }, set []))
67+
68+
(5,19)-(5,20) parse error Unexpected symbol '=' in expression
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Module
2+
3+
async {
4+
use! res: = async { return 1 }
5+
return res
6+
}

0 commit comments

Comments
 (0)