Skip to content

Commit

Permalink
Fix ConvertToSwitchExpression when SwitchStatement is empty.
Browse files Browse the repository at this point in the history
Change-Id: Id7ab8319ff5a9e41b353ed1363ce0d5159fe4ff2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292984
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Apr 3, 2023
1 parent 0386350 commit 525376c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -13,6 +13,7 @@ import 'package:analyzer_plugin/utilities/assist/assist.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_dart.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';
import 'package:collection/collection.dart';

class ConvertToSwitchExpression extends CorrectionProducer {
/// Local variable reference used in assignment switch expression generation.
Expand Down Expand Up @@ -309,7 +310,7 @@ class ConvertToSwitchExpression extends CorrectionProducer {
bool isEffectivelyExhaustive(DartType? type, SwitchStatement node) {
if (type == null) return false;
if ((typeSystem as TypeSystemImpl).isAlwaysExhaustive(type)) return true;
var last = node.members.last;
var last = node.members.lastOrNull;
if (last is SwitchPatternCase) {
var pattern = last.guardedPattern.pattern;
return pattern is WildcardPattern;
Expand Down
Expand Up @@ -297,6 +297,15 @@ String f(String s) {
''');
}

Future<void> test_empty() async {
await resolveTestCode('''
void f(int x) {
switch (x) {}
}
''');
await assertNoAssistAt('(x)');
}

Future<void> test_return_notExhaustive_noAssist() async {
await resolveTestCode('''
String f(int i) {
Expand Down

0 comments on commit 525376c

Please sign in to comment.