diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index ed5da9fd043..e0e450c398f 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -352,6 +352,14 @@ let rec isTypeSeqBlockElementContinuator token = // member x.M1 // member x.M2 | BAR -> true + // Closing tokens for anonymous record types and struct types in type aliases, e.g. + // type T = + // {| Id: int + // |} [] <-- BAR_RBRACE here should not trigger OBLOCKSEP for '[]' + // type T = + // {| Id: int + // |} seq <-- BAR_RBRACE here should not trigger OBLOCKSEP for 'seq' + | BAR_RBRACE -> true | OBLOCKBEGIN | ORIGHT_BLOCK_END _ | OBLOCKEND _ | ODECLEND (_, _) -> true // The following arise during reprocessing of the inserted tokens when we hit a DONE | ODUMMY token -> isTypeSeqBlockElementContinuator token | _ -> false diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs index 69c14a8d418..beef862b27a 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs @@ -673,3 +673,73 @@ let nested2 : {| A: {| B: Expr |}; C: Expr |} = (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.") (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.") ] + +module TypeAliasIndentation = + + // https://github.com/dotnet/fsharp/issues/17992 + [] + let ``Anonymous record type alias with array suffix - closing bracket aligned with opening``() = + FSharp """ +module M +type T = + {| Id: System.Guid + |} [] +""" + |> typecheck + |> shouldSucceed + + [] + let ``Anonymous record type alias with seq postfix - closing bracket aligned with opening``() = + FSharp """ +module M +type T = + {| Id: System.Guid + |} seq +""" + |> typecheck + |> shouldSucceed + + [] + let ``Anonymous record type alias with list postfix - closing bracket aligned with opening``() = + FSharp """ +module M +type T = + {| Id: System.Guid + |} list +""" + |> typecheck + |> shouldSucceed + + [] + let ``Anonymous record type alias with option postfix - closing bracket aligned with opening``() = + FSharp """ +module M +type T = + {| Id: System.Guid + |} option +""" + |> typecheck + |> shouldSucceed + + [] + let ``Anonymous record type alias with multiple fields and array suffix``() = + FSharp """ +module M +type T = + {| Id: System.Guid + Name: string + |} [] +""" + |> typecheck + |> shouldSucceed + + [] + let ``Anonymous record type alias all on same line still works``() = + FSharp """ +module M +type T = {| Id: System.Guid |} [] +type U = {| Id: System.Guid |} seq +type V = {| Id: System.Guid |} list +""" + |> typecheck + |> shouldSucceed