Skip to content

Commit 10c07b3

Browse files
authored
Fix parsing errors using anonymous records and units of measures (#18543)
1 parent fb50b56 commit 10c07b3

File tree

60 files changed

+842
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+842
-22
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
### Fixed
2+
3+
* Fix parsing errors using anonymous records and units of measures ([PR #18543](https://github.com/dotnet/fsharp/pull/18543))
24
* Fixed: Allow `return`, `return!`, `yield`, `yield!` type annotations without parentheses ([PR #18533](https://github.com/dotnet/fsharp/pull/18533))
35
* Allow `let!` and `use!` type annotations without requiring parentheses ([PR #18508](https://github.com/dotnet/fsharp/pull/18508))
46
* Fix find all references for F# exceptions ([PR #18565](https://github.com/dotnet/fsharp/pull/18565))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* Make `[<CallerMemberName; Struct>]` combination work([PR #18444](https://github.com/dotnet/fsharp/pull/18444/))
3131
* Fix code completion considers types from own namespace non-imported ([PR #18518](https://github.com/dotnet/fsharp/issues/18518))
3232
* Code completion: fix getting qualifier expression in do statements in type decls ([PR #18524](https://github.com/dotnet/fsharp/pull/18524))
33+
* Fix parsing errors using anonymous records and units of measures ([PR #18543](https://github.com/dotnet/fsharp/pull/18543))
3334
* Fixed: [#18441](https://github.com/dotnet/fsharp/issues/18441) FSI multi-emit unstable. ([PR #18465](https://github.com/dotnet/fsharp/pull/18465))
3435
* Fixed: Allow `return`, `return!`, `yield`, `yield!` type annotations without parentheses ([PR #18533](https://github.com/dotnet/fsharp/pull/18533))
3536

docs/release-notes/.Language/preview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Support ValueOption + Struct attribute as optional parameter for methods ([Language suggestion #1136](https://github.com/fsharp/fslang-suggestions/issues/1136), [PR #18098](https://github.com/dotnet/fsharp/pull/18098))
77
* Allow `_` in `use!` bindings values (lift FS1228 restriction) ([PR #18487](https://github.com/dotnet/fsharp/pull/18487))
88
* Warn when `unit` is passed to an `obj`-typed argument ([PR #18330](https://github.com/dotnet/fsharp/pull/18330))
9+
* Fix parsing errors using anonymous records and units of measures ([PR #18543](https://github.com/dotnet/fsharp/pull/18543))
910
* Scoped Nowarn: added the #warnon compiler directive ([Language suggestion #278](https://github.com/fsharp/fslang-suggestions/issues/278), [RFC FS-1146 PR](https://github.com/fsharp/fslang-design/pull/782), [PR #18049](https://github.com/dotnet/fsharp/pull/18049))
1011
* Allow `let!` and `use!` type annotations without requiring parentheses. ([PR #18508](https://github.com/dotnet/fsharp/pull/18508))
1112

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ type Exception with
11411141
| Parser.TOKEN_COLON_EQUALS -> SR.GetString("Parser.TOKEN.COLON.EQUALS")
11421142
| Parser.TOKEN_LARROW -> SR.GetString("Parser.TOKEN.LARROW")
11431143
| Parser.TOKEN_EQUALS -> SR.GetString("Parser.TOKEN.EQUALS")
1144+
| Parser.TOKEN_GREATER_BAR_RBRACE -> SR.GetString("Parser.TOKEN.GREATER.BAR.RBRACE")
11441145
| Parser.TOKEN_GREATER_BAR_RBRACK -> SR.GetString("Parser.TOKEN.GREATER.BAR.RBRACK")
11451146
| Parser.TOKEN_MINUS -> SR.GetString("Parser.TOKEN.MINUS")
11461147
| Parser.TOKEN_ADJACENT_PREFIX_OP -> SR.GetString("Parser.TOKEN.ADJACENT.PREFIX.OP")

src/Compiler/FSComp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,7 @@ featureDeprecatePlacesWhereSeqCanBeOmitted,"Deprecate places where 'seq' can be
17991799
featureSupportValueOptionsAsOptionalParameters,"Support ValueOption as valid type for optional member parameters"
18001800
featureSupportWarnWhenUnitPassedToObjArg,"Warn when unit is passed to a member accepting `obj` argument, e.g. `Method(o:obj)` will warn if called via `Method()`."
18011801
featureUseBangBindingValueDiscard,"Allows use! _ = ... in computation expressions"
1802+
featureBetterAnonymousRecordParsing,"Support for better anonymous record parsing"
18021803
featureScopedNowarn,"Support for scoped enabling / disabling of warnings by #warn and #nowarn directives, also inside modules"
18031804
featureAllowLetOrUseBangTypeAnnotationWithoutParens,"Allow let! and use! type annotations without requiring parentheses"
18041805
3874,lexWarnDirectiveMustBeFirst,"#nowarn/#warnon directives must appear as the first non-whitespace characters on a line"

src/Compiler/FSStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@
357357
<data name="Parser.TOKEN.EQUALS" xml:space="preserve">
358358
<value>symbol '='</value>
359359
</data>
360+
<data name="Parser.TOKEN.GREATER.BAR.RBRACE" xml:space="preserve">
361+
<value>symbol '&gt;|}'</value>
362+
</data>
360363
<data name="Parser.TOKEN.GREATER.BAR.RBRACK" xml:space="preserve">
361364
<value>symbol '&gt;|]'</value>
362365
</data>

src/Compiler/Facilities/LanguageFeatures.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type LanguageFeature =
100100
| SupportValueOptionsAsOptionalParameters
101101
| WarnWhenUnitPassedToObjArg
102102
| UseBangBindingValueDiscard
103+
| BetterAnonymousRecordParsing
103104
| ScopedNowarn
104105
| AllowTypedLetOrUseBang
105106

@@ -233,6 +234,7 @@ type LanguageVersion(versionText) =
233234
LanguageFeature.SupportValueOptionsAsOptionalParameters, previewVersion
234235
LanguageFeature.WarnWhenUnitPassedToObjArg, previewVersion
235236
LanguageFeature.UseBangBindingValueDiscard, previewVersion
237+
LanguageFeature.BetterAnonymousRecordParsing, previewVersion
236238
LanguageFeature.ScopedNowarn, previewVersion
237239
LanguageFeature.AllowTypedLetOrUseBang, previewVersion
238240
]
@@ -398,6 +400,7 @@ type LanguageVersion(versionText) =
398400
| LanguageFeature.SupportValueOptionsAsOptionalParameters -> FSComp.SR.featureSupportValueOptionsAsOptionalParameters ()
399401
| LanguageFeature.WarnWhenUnitPassedToObjArg -> FSComp.SR.featureSupportWarnWhenUnitPassedToObjArg ()
400402
| LanguageFeature.UseBangBindingValueDiscard -> FSComp.SR.featureUseBangBindingValueDiscard ()
403+
| LanguageFeature.BetterAnonymousRecordParsing -> FSComp.SR.featureBetterAnonymousRecordParsing ()
401404
| LanguageFeature.ScopedNowarn -> FSComp.SR.featureScopedNowarn ()
402405
| LanguageFeature.AllowTypedLetOrUseBang -> FSComp.SR.featureAllowLetOrUseBangTypeAnnotationWithoutParens ()
403406

src/Compiler/Facilities/LanguageFeatures.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type LanguageFeature =
9191
| SupportValueOptionsAsOptionalParameters
9292
| WarnWhenUnitPassedToObjArg
9393
| UseBangBindingValueDiscard
94+
| BetterAnonymousRecordParsing
9495
| ScopedNowarn
9596
| AllowTypedLetOrUseBang
9697

src/Compiler/Service/ServiceLexing.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ module internal TokenClassifications =
283283
| LBRACE_BAR -> (FSharpTokenColorKind.Punctuation, FSharpTokenCharKind.Delimiter, FSharpTokenTriggerClass.MatchBraces)
284284

285285
| GREATER_RBRACK
286+
| GREATER_BAR_RBRACE
286287
| GREATER_BAR_RBRACK -> (FSharpTokenColorKind.Punctuation, FSharpTokenCharKind.Delimiter, FSharpTokenTriggerClass.None)
287288

288289
| RQUOTE _
@@ -1387,6 +1388,7 @@ type FSharpTokenKind =
13871388
| Comma
13881389
| RightArrow
13891390
| GreaterBarRightBracket
1391+
| GreaterBarRightBrace
13901392
| LeftParenthesisStarRightParenthesis
13911393
| Open
13921394
| Or
@@ -1598,6 +1600,7 @@ type FSharpToken =
15981600
| STAR -> FSharpTokenKind.Star
15991601
| COMMA -> FSharpTokenKind.Comma
16001602
| RARROW -> FSharpTokenKind.RightArrow
1603+
| GREATER_BAR_RBRACE -> FSharpTokenKind.GreaterBarRightBrace
16011604
| GREATER_BAR_RBRACK -> FSharpTokenKind.GreaterBarRightBracket
16021605
| LPAREN_STAR_RPAREN -> FSharpTokenKind.LeftParenthesisStarRightParenthesis
16031606
| OPEN -> FSharpTokenKind.Open

src/Compiler/Service/ServiceLexing.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ type public FSharpTokenKind =
457457
| Comma
458458
| RightArrow
459459
| GreaterBarRightBracket
460+
| GreaterBarRightBrace
460461
| LeftParenthesisStarRightParenthesis
461462
| Open
462463
| Or

src/Compiler/SyntaxTree/LexFilter.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ type LexFilterImpl (
10931093
scanAhead nParen
10941094
else
10951095
false
1096-
| GREATER _ | GREATER_RBRACK | GREATER_BAR_RBRACK ->
1096+
| GREATER _ | GREATER_RBRACK | GREATER_BAR_RBRACK | GREATER_BAR_RBRACE ->
10971097
let nParen = nParen - 1
10981098
let hasAfterOp = (match lookaheadToken with GREATER _ -> false | _ -> true)
10991099
if nParen > 0 then
@@ -1201,6 +1201,11 @@ type LexFilterImpl (
12011201
delayToken (pool.UseShiftedLocation(tokenTup, INFIX_AT_HAT_OP "@", 1, 0))
12021202
delayToken (pool.UseShiftedLocation(tokenTup, LESS res, 0, -1))
12031203
pool.Return tokenTup
1204+
| GREATER_BAR_RBRACE ->
1205+
lexbuf.CheckLanguageFeatureAndRecover LanguageFeature.BetterAnonymousRecordParsing lexbuf.LexemeRange
1206+
delayToken (pool.UseShiftedLocation(tokenTup, BAR_RBRACE, 1, 0))
1207+
delayToken (pool.UseShiftedLocation(tokenTup, GREATER res, 0, -2))
1208+
pool.Return tokenTup
12041209
| GREATER_BAR_RBRACK ->
12051210
delayToken (pool.UseShiftedLocation(tokenTup, BAR_RBRACK, 1, 0))
12061211
delayToken (pool.UseShiftedLocation(tokenTup, GREATER res, 0, -2))

src/Compiler/lex.fsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ rule token (args: LexArgs) (skip: bool) = parse
905905

906906
| ">" { GREATER false }
907907

908+
| ">|}" { GREATER_BAR_RBRACE }
909+
908910
| "[<" { LBRACK_LESS }
909911

910912
| "]" { RBRACK }

src/Compiler/pars.fsy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ let parse_error_rich = Some(fun (ctxt: ParseErrorContext<_>) ->
8484
%token EXCEPTION FALSE FOR FUN FUNCTION IF IN JOIN_IN FINALLY DO_BANG
8585
%token LAZY OLAZY MATCH MATCH_BANG MUTABLE NEW OF
8686
%token OPEN OR REC THEN TO TRUE TRY TYPE VAL INLINE INTERFACE INSTANCE CONST
87-
%token WHEN WHILE WHILE_BANG WITH HASH AMP AMP_AMP QUOTE LPAREN RPAREN RPAREN_COMING_SOON RPAREN_IS_HERE STAR COMMA RARROW GREATER_BAR_RBRACK LPAREN_STAR_RPAREN
87+
%token WHEN WHILE WHILE_BANG WITH HASH AMP AMP_AMP QUOTE LPAREN RPAREN RPAREN_COMING_SOON RPAREN_IS_HERE STAR COMMA RARROW GREATER_BAR_RBRACK GREATER_BAR_RBRACE LPAREN_STAR_RPAREN
8888
%token QMARK QMARK_QMARK DOT COLON COLON_COLON COLON_GREATER COLON_QMARK_GREATER COLON_QMARK COLON_EQUALS SEMICOLON
8989
%token SEMICOLON_SEMICOLON LARROW EQUALS LBRACK LBRACK_BAR LBRACE_BAR LBRACK_LESS
9090
%token BAR_RBRACK BAR_RBRACE UNDERSCORE

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ko.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.pl.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ru.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.tr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.zh-Hant.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSStrings.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSStrings.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSStrings.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)