dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.82k stars 773 forks source link

Improve error reporting: "cannot be converted to type" is hard to read when generics involved #17367

Open Thorium opened 6 days ago

Thorium commented 6 days ago

One of our not-so-senior F# devs pasted me this error that is very clearly describing what is the issue:

image

Ok, there is a clear mismatch here, can you spot it?

Spoiler
GroupResultItems implements IGrouping so that would be fine, but the nested generic types don't match. See the red line here! That's why the cast fails.
Fix: You just have to use (0 and 1) vs. (true and false).

Describe the solution you'd like

Ok.. could we do better? Is there a possibility to somehow e.g. add line-breaks to the error message? Forced line break after "Object of type" and another after "cannot be converted to type" would help.

kerams commented 5 days ago

I am going to assume this exception was thrown by a reflected method call, in which case you should petition the runtime/BCL team to adjust the text, but I wouldn't be suprised if they had a reason for keeping error messages single-line.

Thorium commented 5 days ago

Your assumption is correct.