Skip to content

Improve Error Reporting: Better description for mismatched anonymous records. #8091

@isaacabraham

Description

@isaacabraham

What

If the LHS and RHS of an anonymous record expression does not match, the compiler gives a list of all fields on both sides, even if 99 out of 100 fields match.

let foo : {| Name : string; Age : int; DOB : DateTime; Duration : TimeSpan |} =
    {| Age = 10; Foo = true; Bar = false, 10 |}

gives the error

error FS0001: Two anonymous record types have mismatched sets of field names '["Age"; "DOB"; "Duration"; "Name"]' and '["Age"; "Bar"; "Foo"]'

Why

This rapidly becomes difficult to work with on anything but small anonymous records, especially if you simply have a typo in a single field e.g. FullName and Fullname or similar. Often, developers will construct an anonymous record by creating a single field and then "fill in the blanks" based on the compiler error message until all fields are populated.

How

  • Omit fields that already match
  • Show missing fields separately
  • Show extra fields separately

e.g.

error FS0001: Two anonymous record types have mismatched field names. The following fields fields must be added: '["Age"; "DOB"; "Duration"]`. The following fields must be removed: `["Bar; "Foo"]`

For cases where the RHS is a subset or superset, the other part of the error message can be truncated as needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions