Switch-cases completion is missing after Dart 3.0
Steps to Reproduce
- Set the
sdkconstraint to>=3.0.0inpubspec.yamland run pub get. - Try the below code.
enum MyEnum { foo, bar }
void f(MyEnum e) {
switch (e) {}
}
Version info
[√] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1848], locale en-US)
• Flutter version 3.10.5 on channel stable at X:\SDK\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 796c8ef792 (3 weeks ago), 2023-06-13 15:51:02 -0700
• Engine revision 45f6e00911
• Dart version 3.0.5
• DevTools version 2.23.1
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
I can't tell where the cursor is. If it is between the braces (i.e. the | in this: {|}) then this is a problem with the analyzer. If it is somewhere else then I think it is ok.
No, the cursor is pointing to the switch keyword. This is easy to reproduce, just switch on any enumeration value and you'll see it.
@bwilkerson @scheglov What completion should be expected in this case?
Given that ( and ) are highlighted, I think the caret is at one or another.
In this case, we get
If I put the caret at switch, I get
Testing on IDEA 2023.1, Windows
https://github.com/flutter/flutter-intellij/assets/15884415/974e0446-afe6-4760-ace3-30e1e5cde43b
Testing on IDEA 2023.1, macOS
https://github.com/flutter/flutter-intellij/assets/15884415/4896248d-6e45-4c4f-8998-7b5671ea48a9
When the SDK constraint was set to >=3.0.0, the issue occurred, if your project has a constraint like >=2.19.0, it won't break at all. I've updated the top comment with this info.
@AlexV525 I can confirm that this problem exists with the current stable SDK. However, it is fixed in master, as @scheglov's screen shot shows, and my own test confirmed. See https://github.com/dart-lang/sdk/issues/52607
Also see https://github.com/dart-lang/sdk/issues/52180 for why it only inserts a single case now.
Oddly, it will do all of them eventually, but only one at a time. Seems like the quick fix could automatically run itself until it doesn't find any more. @bwilkerson is that feasible?
https://github.com/dart-lang/sdk/issues/51985 is open because we need support from _fe_analyzer_shared to get more than one witness for a failed exhaustiveness validation. But I don't think this is high priority.
I'm against adding workarounds like running the fix multiple time. This is not the level at which the problem should be fixed.
I wonder if we could do it in the IDE? I don't know when I'd have time to investigate, but I'll keep this open as a reminder.
Can confirm it's working (add 1 missing case at once) on the main channel of Flutter.
Seems like the quick fix could automatically run itself until it doesn't find any more. @bwilkerson is that feasible?
Maybe. There are a few potential blockers:
- it might not be fast enough
- the edits might not be composable
- it might not be possible to update the file state for re-analysis purposes without causing chaos in the UI
But I agree with Konstantin that this isn't the preferred way to solve the problem, and I'd rather put resources toward the better solution if at all possible. If someone did implement an iterative approach I'd consider it to be technical debt that needed to be cleaned up, and we don't need more technical debt.
Any updates?
Please fix this! It still happens in December 2023.