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
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.
The text was updated successfully, but these errors were encountered:
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.
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.
gives the error
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
andFullname
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
e.g.
For cases where the RHS is a subset or superset, the other part of the error message can be truncated as needed.
The text was updated successfully, but these errors were encountered: