-
Notifications
You must be signed in to change notification settings - Fork 1.7k
dart fix
applies fixes in part files mutliple times
#59572
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
/fyi @bwilkerson |
Is this a recent regression? |
from the issue i had opened today:
|
Working on reproducing this in https://dart-review.googlesource.com/c/sdk/+/401180, I'm not seeing it at the bulk_fix level in the server but it does reproduce in the /fyi @bwilkerson |
Hmmmm, or maybe not quite. Reducing
Interestingly, with the default of 4
|
My guess (I've not looked into anything) is that this has something to do with the new element model/enhanced parts changes. Maybe some of the new logic with that was already on that version for the analysis done here? |
@FMorschel: totally and that's my thinking too but I haven't found what level the problem is occurring in. (Unfortunately, the only place I have it reproduced, in the |
UPDATE: will return to this tomorrow but it may take some bissecting. In particular, I'll be curious to see if the current error reproduces before 73adec7 (which does the initial migration) and is in 3.7.0-157.0.dev (where the OP initially reported the issue). |
@pq an update for you: I've tested downloading the SDK from https://gsdview.appspot.com/dart-archive/channels/main/raw/hash/5c904c17f79f2dc2374b4619dad354bd2a293ea0/sdk/ (parent commit from the one you mentioned). The error is already there. |
After some testing, still no results but I have a starting theory. When it does the first analysis for the part file, I think it is counting:
I'm unsure why would it do such a thing, but it's a theory. I think something is not working right for calculating the fixes for the part file. |
Just to make sure the duplicate issue didn't get drowned out, but the bug already exists in the currently released stable version of Dart 3.6.0. And as a further data point (and maybe more head scratching), if you introduce lints for Additionally, if you modify ;
b();` you write (error instead of lint) idontexist(); the fix for
Further testing also shows, that if you switch the content of For example: // a.dart
part 'b.dart';
Stream<String> b() {
// dart fix should only add a single const
return Stream.empty();
}
// b.dart
part of 'a.dart';
// triggers the 4 const + 1 duplicated_modifier fix
idontexist
// triggers the 3 const fix
void a {
;
}
// these don't trigger the bug
idontexist;
idontexist()
idontexist(); |
That is because when you have them applied, they don't re-trigger the diagnostic (see the screenshots in my comment above).
I've never heard of it before and I couldn't find any docs besides the one for Rust. But the weird thing is that "fixing" it does nothing (because it is not there and should not be showing up so maybe a separate issue).
You may be onto something here. Probably what I suggested for the diagnostic count being off. Edit@pq commented
Yeah, I'm not sure where the cut is for the 3.6 stable version (which commit) but I don't think it is on |
It doesn't exist as a lint, but it exists: sdk/pkg/front_end/messages.yaml Lines 1259 to 1261 in e8dafed
And it does remove one |
I see, in this case, we may have a bug in the parser for this with only two Also, we might need to add docs to EditHere it is #59738, @denniskaselow. |
@denniskaselow for the Since it now still has an error on main.dart, it'll look for all the errors in the library (any or both files) and show this fix (for |
Thanks all for the detective work! |
I think I figured it out @pq. Asked on Discord for more help on how to debug, but the problem is in one of the tests you made on the CL. Commenting here too for future reference: In I'd expect that when you resolve for test code (on the mentioned test) you only get the results for that file, and not part too. Or if this returned fixes for two files, for |
Thanks for looking! With this clue I was able to get the issue reproduced in (It turns out, I wasn't looking deeply enough into the edit results.) These new expectations do it: var result = await sendEditBulkFixes([sourceDirectory.path]);
var edits = result.edits;
expect(edits, hasLength(2));
expect(edits[0].edits, hasLength(1));
expect(edits[1].edits, hasLength(1));
This will be far easier to debug from. Thanks! |
@pq, I'm looking at this as well, but feel free to do so, you're probably more familiar with all of this than me. I've pinged you on a Discord thread related to this. Hopefully, we can find a good solution soon. |
@pq I think I've made a small change that fixes it. Inside /// Uses the change [builder] to create fixes for the diagnostics in the
/// library associated with the analysis [libraryResult].
Future<void> _fixErrorsInLibraryAt(
ResolvedLibraryResult libraryResult, {
required String path,
bool stopAfterFirst = false,
bool autoTriggered = false,
}) async {
for (var unitResult in libraryResult.units) {
if (unitResult.path != path) {
continue;
}
await _fixErrorsInLibraryUnit(
libraryResult,
unitResult,
stopAfterFirst: stopAfterFirst,
autoTriggered: autoTriggered,
);
}
} |
Not quite, under Do you want me to make a CL myself or do you want to complete this, @pq? Fyi @bwilkerson I think this issue mentioned above (#55520) is the one that created this issue so about 6 months old. |
Ah! This is fantastic. I'm more than happy to let you land your fix, @FMorschel. Thanks for all of your help! |
Bug: #59572 Change-Id: I6d70f5801b7e7f27ad944a1335b7f0aeba857e2b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401180 Commit-Queue: Phil Quitslund <pquitslund@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
@FMorschel feel free to modify the new tests in 6456180 as suits you. I hope they're useful. |
@pq can I get a review for https://dart-review.googlesource.com/c/sdk/+/401865? Thanks! |
For everyone following this issue, we will open a cherry-pick (CP) issue for this change. Once we have the new issue I'll post the link here too. Thanks, everyone for filing the issues and helping us find the source of the problem! |
Here is the CP link #59853 |
Fixes multiple insertions in multi-file library when using `dart fix`. Merges the test in https://dart-review.googlesource.com/c/sdk/+/401840 that is related to https://dart-review.googlesource.com/c/sdk/+/401180, but in the LSP handler where it can be more easily debugged. Bug #59572 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/401865 Cherry-pick-request: #59853 Change-Id: Ic0c42c4cacb5a270b1d92198819afa6813c83b17 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403380 Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com> Auto-Submit: Felipe Morschel <git@fmorschel.dev> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Dart 3.6.1 is out with a fix! |
Wait, are you sure this shipped in 3.6.1? ![]() |
It should @benthillerkus. It is the last point in the changelog https://github.com/dart-lang/sdk/blob/stable/CHANGELOG.md I'll take a look at your repro and see what I can find. |
@benthillerkus I've tested it locally and I do see that this seems to have not been fixed. I'm asking at the other issue (the one for CP) for what happened here. If you want to follow this go there and subscribe to it. Sorry for the false alarm everyone. I'll update here again only when I see the fix landed and tested by me (with the stable build). |
Alright, everyone. I've just tested the changes at The change I made to stable was pending for too long and got merged just after the 3.6.1 commit for building the SDK. Now, we still have this entry to the changelog mentioning it on 3.6.1 but it actually only got released on 3.6.2. The people who handle this part of the flow for stable releases are already fully aware of what happened but the Changelog itself will only get fixed on the next patch or on the next full version release (see here).
|
This will probably be the last update here. Flutter 3.27.4 is out now with Dart 3.6.2, so if you're running a Flutter project, you can update your SDK to get the fix! |
Thanks a million for pushing this through @FMorschel! |
Dart SDK version: 3.7.0-157.0.dev (dev) (Sat Nov 16 12:03:16 2024 -0800) on "windows_x64"
Running
dart fix --apply
on this code will apply the fixes inb.dart
multiple times:The fix adds
const
3 times inb.dart
:Output of
dart fix --apply
:It's not limited to these lints. For example the fix for
require_trailing_commas
would add multiple commas.The text was updated successfully, but these errors were encountered: