Skip to content

Commit 6b7aa6e

Browse files
auduchinokpsfinaki
andauthored
Parser: more 'as' pattern recovery (#16837)
* Parser: more 'as' pattern recovery * Release notes --------- Co-authored-by: Petr <[email protected]>
1 parent 74e3362 commit 6b7aa6e

File tree

8 files changed

+44
-5
lines changed

8 files changed

+44
-5
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* Add switch to generate types and members with IL visibility that accurately represents their F# visibility. ([PR #15484](https://github.com/dotnet/fsharp/pull/15484)
3232
* Allow returning bool instead of unit option for partial active patterns. ([Language suggestion #1041](https://github.com/fsharp/fslang-suggestions/issues/1041), [PR #16473](https://github.com/dotnet/fsharp/pull/16473))
3333
* Symbols: Add GenericArguments to FSharpEntity ([PR #16470](https://github.com/dotnet/fsharp/pull/16470))
34+
* Parser: more 'as' pattern recovery ([PR #16837](https://github.com/dotnet/fsharp/pull/16837))
3435
* Add extended data for `DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer` (FS0318). ([PR #16811](https://github.com/dotnet/fsharp/pull/16811)))
3536

3637
### Changed

src/Compiler/pars.fsy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3719,6 +3719,12 @@ parenPattern:
37193719
let pat2 = SynPat.Wild(mAs.EndRange)
37203720
SynPat.As($1, pat2, rhs2 parseState 1 2) }
37213721

3722+
| parenPattern AS
3723+
{ let mAs = rhs parseState 2
3724+
let pat2 = SynPat.Wild(mAs.EndRange)
3725+
reportParseErrorAt mAs (FSComp.SR.parsExpectingPattern ())
3726+
SynPat.As($1, pat2, rhs2 parseState 1 2) }
3727+
37223728
| parenPattern BAR parenPattern
37233729
{ let mBar = rhs parseState 2
37243730
SynPat.Or($1, $3, rhs2 parseState 1 3, { BarRange = mBar }) }

tests/service/data/SyntaxTree/Pattern/As 02.fs.bsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ ImplFile
2121
{ ConditionalDirectives = []
2222
CodeComments = [] }, set []))
2323

24-
(4,7)-(4,9) parse error Unexpected symbol '->' in pattern
24+
(4,4)-(4,6) parse error Expecting pattern

tests/service/data/SyntaxTree/Pattern/As 05.fs.bsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ ImplFile
2121
{ ConditionalDirectives = []
2222
CodeComments = [] }, set []))
2323

24-
(5,0)-(5,0) parse error Incomplete structured construct at or before this point in pattern
25-
(3,13)-(3,17) parse error Unexpected end of input in 'match' or 'try' expression
24+
(4,4)-(4,6) parse error Expecting pattern
25+
(5,0)-(5,0) parse error Incomplete structured construct at or before this point in pattern matching. Expected '->' or other token.

tests/service/data/SyntaxTree/Pattern/As 08.fs.bsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ ImplFile
2020
{ ConditionalDirectives = []
2121
CodeComments = [] }, set []))
2222

23-
(5,0)-(5,1) parse error Unexpected symbol '|' in pattern
23+
(4,4)-(4,6) parse error Expecting pattern

tests/service/data/SyntaxTree/Pattern/As 10.fs.bsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ ImplFile
2222
{ ConditionalDirectives = []
2323
CodeComments = [] }, set []))
2424

25-
(3,10)-(3,11) parse error Unexpected symbol ')' in pattern
25+
(3,7)-(3,9) parse error Expecting pattern
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Module
2+
3+
match a with
4+
| :? T as
5+
6+
()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ImplFile
2+
(ParsedImplFileInput
3+
("/root/Pattern/As 12.fs", false, QualifiedNameOfFile Module, [], [],
4+
[SynModuleOrNamespace
5+
([Module], false, NamedModule,
6+
[Expr
7+
(Match
8+
(Yes (3,0--3,12), Ident a,
9+
[SynMatchClause
10+
(As
11+
(IsInst
12+
(LongIdent (SynLongIdent ([T], [], [None])),
13+
(4,2--4,6)), Wild (4,9--4,9), (4,2--4,9)), None,
14+
ArbitraryAfterError ("patternClauses2", (4,9--4,9)),
15+
(4,2--4,9), Yes, { ArrowRange = None
16+
BarRange = Some (4,0--4,1) })],
17+
(3,0--4,9), { MatchKeyword = (3,0--3,5)
18+
WithKeyword = (3,8--3,12) }), (3,0--4,9));
19+
Expr (Const (Unit, (6,0--6,2)), (6,0--6,2))],
20+
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
21+
(1,0--6,2), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
22+
{ ConditionalDirectives = []
23+
CodeComments = [] }, set []))
24+
25+
(4,7)-(4,9) parse error Expecting pattern
26+
(6,0)-(6,1) parse error Incomplete structured construct at or before this point in pattern matching. Expected '->' or other token.

0 commit comments

Comments
 (0)