mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 11:03:19 +00:00
don't replace is{Not}Empty for nullable targets
Fixes: https://github.com/dart-lang/sdk/issues/55250 Change-Id: Iae692c0f6a36e7fc89028acd1934580d1648c937 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359262 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
parent
ef3eb6b301
commit
4145eeba06
|
@ -7,6 +7,7 @@ import 'package:analysis_server/src/services/correction/fix.dart';
|
|||
import 'package:analyzer/dart/analysis/results.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
||||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
|
||||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
|
||||
import 'package:analyzer_plugin/utilities/range_factory.dart';
|
||||
|
@ -36,6 +37,12 @@ class ReplaceWithIsEmpty extends ResolvedCorrectionProducer {
|
|||
return;
|
||||
}
|
||||
|
||||
// Skip nullable targets.
|
||||
if (replacement.lengthTarget.staticType?.nullabilitySuffix ==
|
||||
NullabilitySuffix.question) {
|
||||
return;
|
||||
}
|
||||
|
||||
var target = utils.getNodeText(replacement.lengthTarget);
|
||||
var getter = replacement.getter;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
|
|
|
@ -122,4 +122,14 @@ f(List c) {
|
|||
}
|
||||
''');
|
||||
}
|
||||
|
||||
/// https://github.com/dart-lang/sdk/issues/55250
|
||||
Future<void> test_nullableList() async {
|
||||
await resolveTestCode('''
|
||||
bool f(List<String>? l) {
|
||||
return l?.length == 0;
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,4 +74,14 @@ f(List c) {
|
|||
}
|
||||
''');
|
||||
}
|
||||
|
||||
/// https://github.com/dart-lang/sdk/issues/55250
|
||||
Future<void> test_nullableList() async {
|
||||
await resolveTestCode('''
|
||||
f(List? c) {
|
||||
if (c?.length != 0) {}
|
||||
}
|
||||
''');
|
||||
await assertNoFix();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue