Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,26 @@ module AnonRecd =
"""
|> compile
|> shouldFail
|> withErrorCode 3523
|> withErrorCode 3523

[<Fact>]
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."
]