File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed
test/src/dart/resolution/type_inference Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import 'package:analyzer/dart/element/element.dart';
7
7
import 'package:analyzer/dart/element/type.dart' ;
8
8
import 'package:analyzer/dart/element/type_provider.dart' ;
9
9
import 'package:analyzer/src/dart/element/type.dart' ;
10
+ import 'package:analyzer/src/dart/element/type_demotion.dart' ;
10
11
import 'package:analyzer/src/generated/resolver.dart' ;
11
12
import 'package:analyzer/src/generated/type_system.dart' ;
12
13
import 'package:meta/meta.dart' ;
@@ -97,7 +98,7 @@ class BodyInferenceContext {
97
98
_typeSystem.isSubtypeOf2 (actualReturnedType, contextType)) {
98
99
clampedReturnedType = actualReturnedType;
99
100
} else {
100
- clampedReturnedType = contextType;
101
+ clampedReturnedType = nonNullifyType (_typeSystem, contextType) ;
101
102
}
102
103
103
104
if (_isGenerator) {
Original file line number Diff line number Diff line change @@ -51,8 +51,6 @@ class FunctionExpressionResolver {
51
51
}
52
52
53
53
var contextType = InferenceContext .getContext (node);
54
- contextType = nonNullifyType (_typeSystem, contextType);
55
-
56
54
if (contextType is FunctionType ) {
57
55
contextType = _matchFunctionTypeParameters (
58
56
node.typeParameters,
@@ -110,6 +108,8 @@ class FunctionExpressionResolver {
110
108
if (_migrationResolutionHooks != null ) {
111
109
inferredType = _migrationResolutionHooks
112
110
.modifyInferredParameterType (p, inferredType);
111
+ } else {
112
+ inferredType = nonNullifyType (_typeSystem, inferredType);
113
113
}
114
114
if (! inferredType.isDynamic) {
115
115
p.type = inferredType;
Original file line number Diff line number Diff line change @@ -429,6 +429,38 @@ void f() {
429
429
_assertReturnType ('(a) {' , 'int' );
430
430
}
431
431
432
+ test_contextFunctionType_nonNullify_returnType_takeActual () async {
433
+ newFile ('/test/lib/a.dart' , content: r'''
434
+ // @dart = 2.7
435
+
436
+ void foo(int Function() x) {}
437
+ ''' );
438
+ await assertNoErrorsInCode ('''
439
+ import 'a.dart';
440
+
441
+ void test(int? a) {
442
+ foo(() => a);
443
+ }
444
+ ''' );
445
+ _assertReturnType ('() => a' , 'int?' );
446
+ }
447
+
448
+ test_contextFunctionType_nonNullify_returnType_takeContext () async {
449
+ newFile ('/test/lib/a.dart' , content: r'''
450
+ // @dart = 2.7
451
+
452
+ void foo(int Function() x) {}
453
+ ''' );
454
+ await assertNoErrorsInCode ('''
455
+ import 'a.dart';
456
+
457
+ void test(dynamic a) {
458
+ foo(() => a);
459
+ }
460
+ ''' );
461
+ _assertReturnType ('() => a' , 'int' );
462
+ }
463
+
432
464
test_contextFunctionType_returnType_async_blockBody_objectQ () async {
433
465
await assertNoErrorsInCode ('''
434
466
T foo<T>() => throw 0;
You can’t perform that action at this time.
0 commit comments