diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index f18525f47f..d63598d532 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -4353,8 +4353,9 @@ and TcTypeOrMeasure kindOpt (cenv: cenv) newOk checkConstraints occ (iwsam: Warn | SynType.Tuple(isStruct, segments, m) -> TcTupleType kindOpt cenv newOk checkConstraints occ env tpenv isStruct segments m - | SynType.AnonRecd(_, [],m) -> - error(Error((FSComp.SR.tcAnonymousTypeInvalidInDeclaration()), m)) + | SynType.AnonRecd(fields = []) -> + // The parser takes care of error messages + NewErrorType(), tpenv | SynType.AnonRecd(isStruct, args, m) -> TcAnonRecdType cenv newOk checkConstraints occ env tpenv isStruct args m diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs index 32ec8b2962..e9dbe8ffd4 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs @@ -42,4 +42,26 @@ module AnonRecd = """ |> compile |> shouldFail - |> withErrorCode 3523 \ No newline at end of file + |> withErrorCode 3523 + + [] + let ``Anonymous record types with parser errors or no fields do not produce overlapping diagnostics`` () = + FSharp """ +module AnonRecd + +type ContactMethod = + | Address of {| Line1 : string; Line 2 : string; Postcode : string |} + +let (x: {| |}) = () + +type ErrorResponse = + { error: {| type : string + message : string |} } +""" + |> typecheck + |> shouldFail + |> withDiagnostics [ + Error 10, Line 5, Col 42, Line 5, Col 43, "Unexpected integer literal in field declaration. Expected ':' or other token." + Error 10, Line 7, Col 12, Line 7, Col 14, "Unexpected symbol '|}' in field declaration. Expected identifier or other token." + Error 10, Line 10, Col 17, Line 10, Col 21, "Incomplete structured construct at or before this point in field declaration. Expected identifier or other token." + ] \ No newline at end of file