-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Assignment errors on complex Function/Record types are unreadable #60543
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
Comments
I'd also like to point out that no types added to the current diagnostic messages are highlighted. Nothing like the below definition for typedef as displayed on the screenshot above. Maybe we could think of a way to make this possible? I'm unsure if VS Code accepts this kind of formatting today without a markdown code block (CC @DanTup). |
If we can't render diffs, there's always the option of having longer messages. Like:
This is similar to versioning conflicts when running |
Right now, VS Code/LSP don't support formatting/markdown for the diagnostic text - see microsoft/vscode#54272 |
Today, I found a similar case where a simple typo in a field for a Record typedef lost me some minutes trying to understand the problem (issue to show I had something like: typedef MyRecord = ({
int foo,
String bar,
List<String> baz,
Map<String, String> field, // Correctly spelled
});
void foo(MyRecord record) {}
void bar() {
foo((
foo: 1,
bar: '',
baz: [],
filed: {}, // Typo, the `e` is in the wrong place
));
} The start of the message is:
On the latest main, we also have more info which would have helped, but my production Flutter app is developed on Stable, so this part was still not showing:
This info already helps a lot, but I wonder, since we have this info, couldn't we make this diagnostic show only in that field? |
It looks like the code for this is here: sdk/pkg/analyzer/lib/src/generated/error_detection_helpers.dart Lines 154 to 156 in 1a6755c
It's in a loop, so my guess is that there could be multiple of these (eg. if you have two unexpected names). Diagnostics do support "context messages" which have locations see line 169) so maybe each field could be added as a context message with that field? I'm not sure exactly how it would appear though. Edit: To clarify, the context messages show as additional lines, collapsed under a diagnostic in VS Code. I really meant I don't know how it would feel like there without trying it out. |
This extra debug util looks nice but: It seems unique to Records. Functions should get it too. Both Records and Functions are a form of Structural typing, so they have the same root issue. |
Here's an error I came across recently:
Where the code is a tearOff:
It goes to say that this error message is pretty much useless due to how much information overload there is.
The root of the issue IMO is: For Functions/Records, just logging the entire type isn't enough.
I think it would be massively helpful if:
diff
or some special colourHere's an example of what I think
Consider:
The current error message is:
I think it'd be more more readable if we instead had:
The text was updated successfully, but these errors were encountered: