-
Notifications
You must be signed in to change notification settings - Fork 790
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: Forgetting | in anonymous record gives a confusing error message. #8127
Comments
I assume you mean comparing when the expected and given type is non-anonymous? Cause comparing field names for anonymous records is currently underway here: #8094. The related issue is #8091 (edit: I'm sure you're aware, it's your PR ;). Totally agree to the suggested improvements. I'd like to add that the inverse is also not as clear as it could be. Perhaps we could improve the general case by mentioning that the expected type is a record and the given type an anonymous record, and vv: One suggestion for improvement here could be:
|
@isaacabraham, I haven't dealt with this area, but it looks like dealing with fsharp/src/fsharp/NameResolution.fs Lines 3192 to 3204 in 4d1e140
the issue is that I don't know if there is tracking of anonymous record types fields the way it is stored in |
What
Whilst it's an expected pattern to move from anonymous records to nominal records, we've noticed that we sometimes find it useful to go the other direction - from a full nominal record to an anonymous record with a type alias.
Unfortunately, doing this leads to an error message that is especially misleading - and leads to lots of confusion (I'm talking sometimes 5 minutes of chasing our tails until we realise what the problem is).
This code compiles fine:
Now assume we change
Person
to an type-aliased anonymous record:Why
Whilst it's totally reasonable to give a compiler error at this point, the error is misleading - it suggests that the
Name
field doesn't exist: The first thing a developer does at this point is look at the type alias and say "Yes, theName
does exist! There's a problem with the compiler!".The developer might completely overlook the fact that they are missing the
|
from the RHS of the second line. Also consider that this second line might exist in another file, or even project, miles away from the alias definition.How
Detect if you're comparing or assigning a nominal record to an aliased record (and, ideally, compare all the field names). Then give an error message such as:
The text was updated successfully, but these errors were encountered: