You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve Error Reporting: Better description for mismatched anonymous records. #8091
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.
letfoo:{| 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.
Reacted by Andrii Maksymets, Christopher Nikkel, Abel Braaksma and Eugene Auduchinok
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.
@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.
Activity
isaacabraham commentedon Jan 5, 2020
At the risk of falling into the world of biksehedding, what style of message do people prefer:
1. Single line, short
2. Single line, verbose
3. Multi line, verbose
Currently I'm leaning towards a multi-line approach as it is a bit clearer to read on the eye.
abelbraaksma commentedon 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:
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.