Skip to content

Commit bc8a51b

Browse files
CopilotT-GroCopilot
authored
Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned (#19762)
* Initial plan * Fix anonymous record type alias with array/generic type suffix error when closing bracket is aligned with opening bracket Add BAR_RBRACE to isTypeSeqBlockElementContinuator in LexFilter.fs to prevent incorrect OBLOCKSEP insertion after closing |} in type alias contexts. This fixes the error 'Unexpected symbol [' in member definition' when writing: type T = {| Id: Guid |} [] // or |} seq, |} list, |} option Add tests covering the fixed cases in AnonymousRecords.fs. Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/efa54b78-f657-43e6-a50e-05db045cba9d Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> * Add release notes for anonymous record type alias parser fix Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> Co-authored-by: Tomas Grosup <tomasgrosup@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Tomas Grosup <Tomas.Grosup@gmail.com>
1 parent 37e58b0 commit bc8a51b

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
* Fix parallel compilation of scripts ([PR #19649](https://github.com/dotnet/fsharp/pull/19649))
6565
* Fix parser recovery, name resolution, and code completion for unfinished enum patterns ([PR #19708](https://github.com/dotnet/fsharp/pull/19708))
6666
* Parser: fix unexpected diagnostics in debug builds, improve error messages ([PR #19730](https://github.com/dotnet/fsharp/pull/19730))
67+
* Fix parser error for anonymous record type aliases with postfix type operators (e.g. `{| Id: Guid |} []`) when closing bracket is column-aligned with opening bracket. ([Issue #17407](https://github.com/dotnet/fsharp/issues/17407), [PR #19762](https://github.com/dotnet/fsharp/pull/19762))
6768
* Fix internal error when resolving SRTP `get_Item` witness for `string` indexers (`unknown builtin witness 'get_ItemDynamic'`). ([Issue #18093](https://github.com/dotnet/fsharp/issues/18093), [PR #19757](https://github.com/dotnet/fsharp/pull/19757))
6869
* Allow `| null` nullable annotation on a `[<MeasureAnnotatedAbbreviation>]` over a reference type (e.g. the FSharp.UMX `type string<[<Measure>] 'm> = string` pattern). ([Issue #19657](https://github.com/dotnet/fsharp/issues/19657))
6970
* Fix `[<Struct>] ?param` optional parameters could not be passed using the explicit `?param = expr` caller-side syntax with a `ValueOption` value. ([Issue #19711](https://github.com/dotnet/fsharp/issues/19711), [PR #19742](https://github.com/dotnet/fsharp/pull/19742))

src/Compiler/SyntaxTree/LexFilter.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ let rec isTypeSeqBlockElementContinuator token =
352352
// member x.M1
353353
// member x.M2
354354
| BAR -> true
355+
// Closing tokens for anonymous record types and struct types in type aliases, e.g.
356+
// type T =
357+
// {| Id: int
358+
// |} [] <-- BAR_RBRACE here should not trigger OBLOCKSEP for '[]'
359+
// type T =
360+
// {| Id: int
361+
// |} seq <-- BAR_RBRACE here should not trigger OBLOCKSEP for 'seq'
362+
| BAR_RBRACE -> true
355363
| OBLOCKBEGIN | ORIGHT_BLOCK_END _ | OBLOCKEND _ | ODECLEND (_, _) -> true // The following arise during reprocessing of the inserted tokens when we hit a DONE
356364
| ODUMMY token -> isTypeSeqBlockElementContinuator token
357365
| _ -> false

tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,3 +673,73 @@ let nested2 : {| A: {| B: Expr<int> |}; C: Expr |} =
673673
(Error 3350, Line 8, Col 22, Line 8, Col 24, "Feature 'Support for better anonymous record parsing' is not available in F# 9.0. Please use language version 10.0 or greater.")
674674
(Error 3350, Line 8, Col 44, Line 8, Col 49, "Feature 'Support for better anonymous record parsing' is not available in F# 9.0. Please use language version 10.0 or greater.")
675675
]
676+
677+
module TypeAliasIndentation =
678+
679+
// https://github.com/dotnet/fsharp/issues/17992
680+
[<Fact>]
681+
let ``Anonymous record type alias with array suffix - closing bracket aligned with opening``() =
682+
FSharp """
683+
module M
684+
type T =
685+
{| Id: System.Guid
686+
|} []
687+
"""
688+
|> typecheck
689+
|> shouldSucceed
690+
691+
[<Fact>]
692+
let ``Anonymous record type alias with seq postfix - closing bracket aligned with opening``() =
693+
FSharp """
694+
module M
695+
type T =
696+
{| Id: System.Guid
697+
|} seq
698+
"""
699+
|> typecheck
700+
|> shouldSucceed
701+
702+
[<Fact>]
703+
let ``Anonymous record type alias with list postfix - closing bracket aligned with opening``() =
704+
FSharp """
705+
module M
706+
type T =
707+
{| Id: System.Guid
708+
|} list
709+
"""
710+
|> typecheck
711+
|> shouldSucceed
712+
713+
[<Fact>]
714+
let ``Anonymous record type alias with option postfix - closing bracket aligned with opening``() =
715+
FSharp """
716+
module M
717+
type T =
718+
{| Id: System.Guid
719+
|} option
720+
"""
721+
|> typecheck
722+
|> shouldSucceed
723+
724+
[<Fact>]
725+
let ``Anonymous record type alias with multiple fields and array suffix``() =
726+
FSharp """
727+
module M
728+
type T =
729+
{| Id: System.Guid
730+
Name: string
731+
|} []
732+
"""
733+
|> typecheck
734+
|> shouldSucceed
735+
736+
[<Fact>]
737+
let ``Anonymous record type alias all on same line still works``() =
738+
FSharp """
739+
module M
740+
type T = {| Id: System.Guid |} []
741+
type U = {| Id: System.Guid |} seq
742+
type V = {| Id: System.Guid |} list
743+
"""
744+
|> typecheck
745+
|> shouldSucceed

0 commit comments

Comments
 (0)