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';
77import 'package:analyzer/dart/element/type.dart' ;
88import 'package:analyzer/dart/element/type_provider.dart' ;
99import 'package:analyzer/src/dart/element/type.dart' ;
10+ import 'package:analyzer/src/dart/element/type_demotion.dart' ;
1011import 'package:analyzer/src/generated/resolver.dart' ;
1112import 'package:analyzer/src/generated/type_system.dart' ;
1213import 'package:meta/meta.dart' ;
@@ -97,7 +98,7 @@ class BodyInferenceContext {
9798 _typeSystem.isSubtypeOf2 (actualReturnedType, contextType)) {
9899 clampedReturnedType = actualReturnedType;
99100 } else {
100- clampedReturnedType = contextType;
101+ clampedReturnedType = nonNullifyType (_typeSystem, contextType) ;
101102 }
102103
103104 if (_isGenerator) {
Original file line number Diff line number Diff line change @@ -51,8 +51,6 @@ class FunctionExpressionResolver {
5151 }
5252
5353 var contextType = InferenceContext .getContext (node);
54- contextType = nonNullifyType (_typeSystem, contextType);
55-
5654 if (contextType is FunctionType ) {
5755 contextType = _matchFunctionTypeParameters (
5856 node.typeParameters,
@@ -110,6 +108,8 @@ class FunctionExpressionResolver {
110108 if (_migrationResolutionHooks != null ) {
111109 inferredType = _migrationResolutionHooks
112110 .modifyInferredParameterType (p, inferredType);
111+ } else {
112+ inferredType = nonNullifyType (_typeSystem, inferredType);
113113 }
114114 if (! inferredType.isDynamic) {
115115 p.type = inferredType;
Original file line number Diff line number Diff line change @@ -429,6 +429,38 @@ void f() {
429429 _assertReturnType ('(a) {' , 'int' );
430430 }
431431
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+
432464 test_contextFunctionType_returnType_async_blockBody_objectQ () async {
433465 await assertNoErrorsInCode ('''
434466T foo<T>() => throw 0;
You can’t perform that action at this time.
0 commit comments