File tree Expand file tree Collapse file tree 4 files changed +35
-6
lines changed
lib/src/services/correction/dart
test/src/services/correction/fix
analyzer/lib/src/dart/element Expand file tree Collapse file tree 4 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 5
5
import 'package:analysis_server/src/services/correction/fix.dart' ;
6
6
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart' ;
7
7
import 'package:analyzer/dart/ast/ast.dart' ;
8
+ import 'package:analyzer/dart/element/nullability_suffix.dart' ;
8
9
import 'package:analyzer/src/dart/ast/extensions.dart' ;
9
10
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart' ;
10
11
import 'package:analyzer_plugin/utilities/fixes/fixes.dart' ;
@@ -47,8 +48,8 @@ class MakeReturnTypeNullable extends ResolvedCorrectionProducer {
47
48
48
49
if (node is ! NullLiteral &&
49
50
! typeSystem.isAssignableTo (
50
- returnType.typeOrThrow ,
51
- typeSystem. promoteToNonNull (type ),
51
+ type ,
52
+ returnType.typeOrThrow. withNullability ( NullabilitySuffix .question ),
52
53
strictCasts: analysisOptions.strictCasts,
53
54
)) {
54
55
return ;
Original file line number Diff line number Diff line change @@ -32,8 +32,6 @@ class ReplaceReturnType extends ResolvedCorrectionProducer {
32
32
Future <void > compute (ChangeBuilder builder) async {
33
33
var node = this .node;
34
34
if (node is Expression ) {
35
- var typeSystem = libraryElement2.typeSystem;
36
-
37
35
var newType = node.staticType;
38
36
39
37
void updateNewType (SyntacticEntity entity) {
Original file line number Diff line number Diff line change 4
4
5
5
import 'package:analysis_server/src/services/correction/fix.dart' ;
6
6
import 'package:analyzer_plugin/utilities/fixes/fixes.dart' ;
7
+ import 'package:analyzer_testing/utilities/utilities.dart' ;
7
8
import 'package:test_reflective_loader/test_reflective_loader.dart' ;
8
9
9
10
import 'fix_processor.dart' ;
@@ -146,6 +147,21 @@ class B extends A {
146
147
await assertNoFix ();
147
148
}
148
149
150
+ Future <void > test_nullable_type () async {
151
+ await resolveTestCode ('''
152
+ int? f(String v) => v;
153
+ ''' );
154
+ await assertNoFix ();
155
+ }
156
+
157
+ Future <void > test_nullable_type_dynamic () async {
158
+ writeAnalysisOptionsFile (analysisOptionsContent (strictCasts: true ));
159
+ await resolveTestCode ('''
160
+ int? f(dynamic v) => v;
161
+ ''' );
162
+ await assertNoFix ();
163
+ }
164
+
149
165
Future <void > test_returnTypeHasTypeArguments () async {
150
166
await resolveTestCode ('''
151
167
List<String> f() {
@@ -158,4 +174,12 @@ List<String>? f() {
158
174
}
159
175
''' );
160
176
}
177
+
178
+ Future <void > test_unrelated_types () async {
179
+ writeAnalysisOptionsFile (analysisOptionsContent (strictCasts: true ));
180
+ await resolveTestCode ('''
181
+ int f(dynamic v) => v;
182
+ ''' );
183
+ await assertNoFix ();
184
+ }
161
185
}
Original file line number Diff line number Diff line change @@ -713,7 +713,10 @@ class TypeSystemImpl implements TypeSystem {
713
713
required covariant InterfaceElementImpl element,
714
714
required NullabilitySuffix nullabilitySuffix,
715
715
}) {
716
- return instantiateInterfaceToBounds (element: element, nullabilitySuffix: nullabilitySuffix);
716
+ return instantiateInterfaceToBounds (
717
+ element: element,
718
+ nullabilitySuffix: nullabilitySuffix,
719
+ );
717
720
}
718
721
719
722
/// Given a [DartType] [type] and a list of types
@@ -753,7 +756,10 @@ class TypeSystemImpl implements TypeSystem {
753
756
required covariant TypeAliasElementImpl element,
754
757
required NullabilitySuffix nullabilitySuffix,
755
758
}) {
756
- return instantiateTypeAliasToBounds (element: element, nullabilitySuffix: nullabilitySuffix);
759
+ return instantiateTypeAliasToBounds (
760
+ element: element,
761
+ nullabilitySuffix: nullabilitySuffix,
762
+ );
757
763
}
758
764
759
765
/// Given uninstantiated [typeFormals] , instantiate them to their bounds.
You can’t perform that action at this time.
0 commit comments