Skip to content

Commit b57ff85

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: clean up and test implicit dynamic return type of Function() syntax.
Change-Id: I6a010f5aa32cee4ece094188992ba472444293c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107519 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 0f2eda8 commit b57ff85

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

pkg/nnbd_migration/lib/src/node_builder.dart

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,6 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType> {
5757
: _nonNullableObjectType =
5858
DecoratedType(_typeProvider.objectType, _graph.never);
5959

60-
/// Creates and stores a [DecoratedType] object corresponding to the given
61-
/// [type] AST, and returns it.
62-
DecoratedType decorateType(TypeAnnotation type, AstNode enclosingNode) {
63-
return type == null
64-
// TODO(danrubel): Return something other than this
65-
// to indicate that we should insert a type for the declaration
66-
// that is missing a type reference.
67-
? new DecoratedType(
68-
DynamicTypeImpl.instance,
69-
NullabilityNode.forInferredDynamicType(
70-
_graph, _source, enclosingNode.offset))
71-
: type.accept(this);
72-
}
73-
7460
@override
7561
DecoratedType visitClassDeclaration(ClassDeclaration node) {
7662
node.metadata.accept(this);
@@ -254,7 +240,7 @@ $stackTrace''');
254240
return decoratedType;
255241
}
256242
var typeArguments = const <DecoratedType>[];
257-
DecoratedType returnType;
243+
DecoratedType decoratedReturnType;
258244
var positionalParameters = const <DecoratedType>[];
259245
var namedParameters = const <String, DecoratedType>{};
260246
if (type is InterfaceType && type.typeParameters.isNotEmpty) {
@@ -272,7 +258,10 @@ $stackTrace''');
272258
}
273259
}
274260
if (node is GenericFunctionType) {
275-
returnType = decorateType(node.returnType, node);
261+
var returnType = node.returnType;
262+
decoratedReturnType = returnType == null
263+
? DecoratedType.forImplicitType(DynamicTypeImpl.instance, _graph)
264+
: returnType.accept(this);
276265
if (node.typeParameters != null) {
277266
// TODO(paulberry)
278267
_unimplemented(node, 'Generic function type with type parameters');
@@ -305,7 +294,7 @@ $stackTrace''');
305294
}
306295
var decoratedType = DecoratedTypeAnnotation(type, nullabilityNode, node.end,
307296
typeArguments: typeArguments,
308-
returnType: returnType,
297+
returnType: decoratedReturnType,
309298
positionalParameters: positionalParameters,
310299
namedParameters: namedParameters);
311300
_variables.recordDecoratedTypeAnnotation(_source, node, decoratedType);

pkg/nnbd_migration/test/api_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,22 @@ int? test(C c) {
862862
await _checkSingleFileChanges(content, expected);
863863
}
864864

865+
test_generic_function_type_syntax_inferred_dynamic_return() async {
866+
var content = '''
867+
abstract class C {
868+
Function() f();
869+
}
870+
Object g(C c) => c.f()();
871+
''';
872+
var expected = '''
873+
abstract class C {
874+
Function() f();
875+
}
876+
Object? g(C c) => c.f()();
877+
''';
878+
await _checkSingleFileChanges(content, expected);
879+
}
880+
865881
test_genericType_noTypeArguments() async {
866882
var content = '''
867883
void f(C c) {}

pkg/nnbd_migration/test/node_builder_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,19 @@ class C {
415415
same(decoratedType));
416416
}
417417

418+
test_generic_function_type_syntax_inferred_dynamic_return() async {
419+
await analyze('''
420+
abstract class C {
421+
Function() f();
422+
}
423+
''');
424+
var decoratedFType = decoratedMethodType('f');
425+
var decoratedFReturnType = decoratedFType.returnType;
426+
var decoratedFReturnReturnType = decoratedFReturnType.returnType;
427+
expect(decoratedFReturnReturnType.type.toString(), 'dynamic');
428+
expect(decoratedFReturnReturnType.node, same(always));
429+
}
430+
418431
test_genericFunctionType_namedParameterType() async {
419432
await analyze('''
420433
void f(void Function({int y}) x) {}

0 commit comments

Comments
 (0)