Skip to content

Commit 9157814

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes "Add import" for Object? variables
Fixes: #60973 Change-Id: Ib31ca4141f1cf29806c38e9ba6bd4b1fdac1f846 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442725 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]>
1 parent a92b585 commit 9157814

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,15 @@ final _builtInNonLintMultiGenerators = {
14041404
CreateMixin.new,
14051405
ImportLibrary.forType,
14061406
],
1407+
CompileTimeErrorCode.UNCHECKED_METHOD_INVOCATION_OF_NULLABLE_VALUE: [
1408+
ImportLibrary.forExtensionMember,
1409+
],
1410+
CompileTimeErrorCode.UNCHECKED_OPERATOR_INVOCATION_OF_NULLABLE_VALUE: [
1411+
ImportLibrary.forExtensionMember,
1412+
],
1413+
CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE: [
1414+
ImportLibrary.forExtensionMember,
1415+
],
14071416
CompileTimeErrorCode.UNDEFINED_ANNOTATION: [
14081417
CreateClass.new,
14091418
ImportLibrary.forTopLevelVariable,

pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,66 @@ void f() { new Foo(); }
972972
);
973973
}
974974

975+
Future<void> test_unchecked_methodInvocation() async {
976+
newFile('$testPackageLibPath/lib.dart', '''
977+
extension E on Object? {
978+
void m() {}
979+
}
980+
''');
981+
await resolveTestCode('''
982+
void f(Object? o) {
983+
o.m();
984+
}
985+
''');
986+
await assertHasFix('''
987+
import 'package:test/lib.dart';
988+
989+
void f(Object? o) {
990+
o.m();
991+
}
992+
''');
993+
}
994+
995+
Future<void> test_unchecked_operatorInvocation() async {
996+
newFile('$testPackageLibPath/lib.dart', '''
997+
extension E on Object? {
998+
int operator +(int other) => 0;
999+
}
1000+
''');
1001+
await resolveTestCode('''
1002+
void f(Object? o) {
1003+
o + 1;
1004+
}
1005+
''');
1006+
await assertHasFix('''
1007+
import 'package:test/lib.dart';
1008+
1009+
void f(Object? o) {
1010+
o + 1;
1011+
}
1012+
''');
1013+
}
1014+
1015+
Future<void> test_unchecked_propertyAccess() async {
1016+
newFile('$testPackageLibPath/lib.dart', '''
1017+
extension E on Object? {
1018+
int get getter => 0;
1019+
}
1020+
''');
1021+
await resolveTestCode('''
1022+
void f(Object? o) {
1023+
o.getter;
1024+
}
1025+
''');
1026+
await assertHasFix('''
1027+
import 'package:test/lib.dart';
1028+
1029+
void f(Object? o) {
1030+
o.getter;
1031+
}
1032+
''');
1033+
}
1034+
9751035
Future<void> test_withClass_annotation() async {
9761036
newFile('$testPackageLibPath/lib.dart', '''
9771037
class Test {

0 commit comments

Comments
 (0)