Improve Error Reporting: Make FS0039 easier to read at a glance.
See original GitHub issueWhat
The following error message is super common and could be made less intimidating:
type Person = { Name : string }
let isaac = { Name = "Isaac" }
let fullName = isaac.Fooo + " Abraham" // The type 'Person' does not define the field, constructor or member 'Fooo'.
Why
The error message makes perfect sense, but for the beginner I feel it could be made more welcoming. In addition, the fact that it shows the type rather than the symbol name is a little confusing - especially if that type has been inferred.
How
I would prefer to see an error something like as follows:
isaac.Fooo
does not exist (isaac
is typePerson
).- Unknown member
isaac.Fooo
(isaac
is typePerson
).
Notice that we use the same symbol name and path as the actual code sample, which hopefully draws people’s attention to the source of the issue. In the current error message, you have to read all the way to the end to see what the issue is.
I suppose we could keep the current “type-oriented” message but still improve it e.g.:
Fooo
does not exist on the typePerson
.Fooo
does not exist on this symbol, which has typePerson
.
I’m not sure when else this error message is shown, so it’s possible I’ve missed some other obvious cases etc.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:11 (5 by maintainers)
Top GitHub Comments
Good point Isaac.
How about:
isaac.Fooo
does not exist (isaac
is of typePerson
, which does not define a field, constructor or memberFooo
)@edgarfgp we actually do that already, as long as the distance is not too far:
The key thing that Elm does here that F# doesn’t is that the error message refers to the symbol (issac) where in F# it simply mentions the type (Person).