Skip to content

Commit 61dffdd

Browse files
authored
Parser: recover on unfinished open (#15377)
1 parent af18bf0 commit 61dffdd

File tree

17 files changed

+187
-5
lines changed

17 files changed

+187
-5
lines changed

src/Compiler/pars.fsy

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ moduleSpfn:
706706
SynModuleSigDecl.Exception(synExnDefn, mWhole) }
707707

708708
| openDecl
709-
{ SynModuleSigDecl.Open($1, (rhs parseState 1)) }
709+
{ SynModuleSigDecl.Open $1 }
710710

711711
valSpfn:
712712
| opt_attributes opt_access VAL opt_attributes opt_inline opt_mutable opt_access nameop opt_explicitValTyparDecls COLON topTypeWithTypeConstraints optLiteralValueSpfn
@@ -1320,15 +1320,26 @@ moduleDefn:
13201320

13211321
/* 'open' declarations */
13221322
| openDecl
1323-
{ [ SynModuleDecl.Open($1, (rhs parseState 1)) ] }
1323+
{ [ SynModuleDecl.Open $1 ] }
13241324

13251325
openDecl:
1326-
/* 'open' declarations */
13271326
| OPEN path
1328-
{ SynOpenDeclTarget.ModuleOrNamespace($2, (rhs parseState 2)) }
1327+
{ let mOpen = rhs parseState 1
1328+
let mPath = $2.Range
1329+
SynOpenDeclTarget.ModuleOrNamespace($2, mPath), unionRanges mOpen mPath }
1330+
1331+
| OPEN recover
1332+
{ let mOpen = rhs parseState 1
1333+
SynOpenDeclTarget.ModuleOrNamespace(SynLongIdent([], [], []), mOpen.EndRange), mOpen }
13291334

13301335
| OPEN typeKeyword appType
1331-
{ SynOpenDeclTarget.Type($3, (rhs parseState 3)) }
1336+
{ let mOpen = rhs parseState 1
1337+
let mPath = $3.Range
1338+
SynOpenDeclTarget.Type($3, mPath), unionRanges mOpen mPath }
1339+
1340+
| OPEN typeKeyword recover
1341+
{ let m = rhs2 parseState 1 2
1342+
SynOpenDeclTarget.ModuleOrNamespace(SynLongIdent([], [], []), m.EndRange), m }
13321343

13331344
/* The right-hand-side of a module abbreviation definition */
13341345
/* This occurs on the right of a module abbreviation (#light encloses the r.h.s. with OBLOCKBEGIN/OBLOCKEND) */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Module
2+
3+
open
4+
open Ns1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/ModuleMember/Open 01.fs", false, QualifiedNameOfFile Module, [], [],
4+
[SynModuleOrNamespace
5+
([Module], false, NamedModule,
6+
[Open
7+
(ModuleOrNamespace (SynLongIdent ([], [], []), (3,4--3,4)),
8+
(3,0--3,4));
9+
Open
10+
(ModuleOrNamespace (SynLongIdent ([Ns1], [], [None]), (4,5--4,8)),
11+
(4,0--4,8))],
12+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
13+
(1,0--4,8), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
14+
{ ConditionalDirectives = []
15+
CodeComments = [] }, set []))
16+
17+
(3,5)-(4,0) parse error Incomplete structured construct at or before this point in open declaration. Expected identifier, 'global', 'type' or other token.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Module
2+
3+
open type
4+
open Ns1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/ModuleMember/Open 02.fs", false, QualifiedNameOfFile Module, [], [],
4+
[SynModuleOrNamespace
5+
([Module], false, NamedModule,
6+
[Open
7+
(ModuleOrNamespace (SynLongIdent ([], [], []), (3,9--3,9)),
8+
(3,0--3,9));
9+
Open
10+
(ModuleOrNamespace (SynLongIdent ([Ns1], [], [None]), (4,5--4,8)),
11+
(4,0--4,8))],
12+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
13+
(1,0--4,8), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
14+
{ ConditionalDirectives = []
15+
CodeComments = [] }, set []))
16+
17+
(3,10)-(4,0) parse error Incomplete structured construct at or before this point in open declaration
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Module
2+
3+
open type
4+
5+
()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/ModuleMember/Open 03.fs", false, QualifiedNameOfFile Module, [], [],
4+
[SynModuleOrNamespace
5+
([Module], false, NamedModule,
6+
[Open
7+
(ModuleOrNamespace (SynLongIdent ([], [], []), (3,9--3,9)),
8+
(3,0--3,9)); Expr (Const (Unit, (5,0--5,2)), (5,0--5,2))],
9+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
10+
(1,0--5,2), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
11+
{ ConditionalDirectives = []
12+
CodeComments = [] }, set []))
13+
14+
(3,10)-(5,0) parse error Incomplete structured construct at or before this point in open declaration
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Module
2+
3+
open type
4+
5+
ignore
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/ModuleMember/Open 04.fs", false, QualifiedNameOfFile Module, [], [],
4+
[SynModuleOrNamespace
5+
([Module], false, NamedModule,
6+
[Open
7+
(ModuleOrNamespace (SynLongIdent ([], [], []), (3,9--3,9)),
8+
(3,0--3,9)); Expr (Ident ignore, (5,0--5,6))],
9+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
10+
(1,0--5,6), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
11+
{ ConditionalDirectives = []
12+
CodeComments = [] }, set []))
13+
14+
(3,10)-(5,0) parse error Incomplete structured construct at or before this point in open declaration
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Module
2+
3+
open
4+
5+
type T = int

0 commit comments

Comments
 (0)