Skip to content

Commit 0f2eda8

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: add support for function expression invocations.
Change-Id: Icf92c81f677421b00f023c02ce784122dd570e87 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107518 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent a200980 commit 0f2eda8

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,9 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType> {
406406
@override
407407
DecoratedType visitFunctionExpressionInvocation(
408408
FunctionExpressionInvocation node) {
409-
// TODO(brianwilkerson)
410-
_unimplemented(node, 'FunctionExpressionInvocation');
409+
DecoratedType calleeType = node.function.accept(this);
410+
return _handleInvocationArguments(node, node.argumentList.arguments,
411+
node.typeArguments, calleeType, null);
411412
}
412413

413414
@override

pkg/nnbd_migration/lib/src/variables.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ class Variables implements VariableRecorder, VariableRepository {
7575
}
7676

7777
void recordDecoratedElementType(Element element, DecoratedType type) {
78-
assert(_graph.isBeingMigrated(element.library.source));
78+
assert(() {
79+
var library = element.library;
80+
if (library == null) {
81+
// No problem; the element is probably a parameter of a function type
82+
// expressed using new-style Function syntax.
83+
} else {
84+
assert(_graph.isBeingMigrated(library.source));
85+
}
86+
return true;
87+
}());
7988
_decoratedElementTypes[element] = type;
8089
}
8190

pkg/nnbd_migration/test/api_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,30 @@ class C {
838838
await _checkSingleFileChanges(content, expected);
839839
}
840840

841+
test_function_expression_invocation() async {
842+
var content = '''
843+
abstract class C {
844+
void Function(int) f();
845+
int/*?*/ Function() g();
846+
}
847+
int test(C c) {
848+
c.f()(null);
849+
return c.g()();
850+
}
851+
''';
852+
var expected = '''
853+
abstract class C {
854+
void Function(int?) f();
855+
int?/*?*/ Function() g();
856+
}
857+
int? test(C c) {
858+
c.f()(null);
859+
return c.g()();
860+
}
861+
''';
862+
await _checkSingleFileChanges(content, expected);
863+
}
864+
841865
test_genericType_noTypeArguments() async {
842866
var content = '''
843867
void f(C c) {}

pkg/nnbd_migration/test/edge_builder_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,4 +2450,30 @@ void f(int i) {
24502450
decoratedTypeAnnotation('int j').node,
24512451
hard: true);
24522452
}
2453+
2454+
test_visitFunctionExpressionInvocation_parameterType() async {
2455+
await analyze('''
2456+
abstract class C {
2457+
void Function(int) f();
2458+
}
2459+
void g(C c, int i) {
2460+
c.f()(i);
2461+
}
2462+
''');
2463+
assertEdge(decoratedTypeAnnotation('int i').node,
2464+
decoratedTypeAnnotation('int)').node,
2465+
hard: true);
2466+
}
2467+
2468+
test_visitFunctionExpressionInvocation_returnType() async {
2469+
await analyze('''
2470+
abstract class C {
2471+
int Function() f();
2472+
}
2473+
int g(C c) => c.f()();
2474+
''');
2475+
assertEdge(decoratedTypeAnnotation('int Function').node,
2476+
decoratedTypeAnnotation('int g').node,
2477+
hard: false);
2478+
}
24532479
}

0 commit comments

Comments
 (0)