Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
isaacabraham opened this issue Jan 4, 2020 · 2 comments · Fixed by #8094
Closed

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

isaacabraham opened this issue Jan 4, 2020 · 2 comments · Fixed by #8094

Comments

@isaacabraham
Copy link
Contributor

@isaacabraham isaacabraham commented Jan 4, 2020

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.

@isaacabraham

This comment has been minimized.

Copy link
Contributor Author

@isaacabraham isaacabraham commented Jan 5, 2020

At the risk of falling into the world of biksehedding, what style of message do people prefer:

1. Single line, short

Anonymous record mismatch. Add missing fields '[ "Foo";  "Bar"]' and remove unexpected extra fields '[ "Baz"; "Bop" ]'.

2. Single line, verbose

This anonymous record does not match the expected shape. Please add the missing fields "Foo" and "Bar", and remove the unexpected extra fields "Baz" and "Bop".

3. Multi line, verbose

This anonymous record does not match the expected shape. Please make the following changes:

* Add the missing fields "Foo" and "Bar"
* Remove the unexpected extra fields "Baz" and "Bop"

Currently I'm leaning towards a multi-line approach as it is a bit clearer to read on the eye.

@abelbraaksma

This comment has been minimized.

Copy link
Contributor

@abelbraaksma abelbraaksma commented Jan 6, 2020

@isaacabraham I'd vote for the multiline approach. However, instead of 'shape' etc, I'd propose a slightly different text, more concise may be easier to read and understand:

Two anonymous records have mismatching fields, either fix the expected type, add the missing fields, or rename or remove the unexpected fields:

* Missing fields: "Foo", "Bar"
* Unexpected fields: "Baz", "Bop"

If there are no missing fields, or if there are no unexpected fields, you might want to fall back to a single line, or just remove the bulleted item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.