Skip to content

Commit 326e970

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: handle method invocations that resolve to a getter.
Change-Id: I9a41190d883ee50a63d8cd60699da14084da09d7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107748 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 822de21 commit 326e970

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType> {
607607
_unimplemented(node, 'Unresolved method name');
608608
}
609609
var calleeType = getOrComputeElementType(callee, targetType: targetType);
610+
if (callee is PropertyAccessorElement) {
611+
calleeType = calleeType.returnType;
612+
}
610613
var expressionType = _handleInvocationArguments(node,
611614
node.argumentList.arguments, node.typeArguments, calleeType, null);
612615
if (isConditional) {

pkg/nnbd_migration/test/api_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,30 @@ int? test(C c) {
938938
await _checkSingleFileChanges(content, expected);
939939
}
940940

941+
test_function_expression_invocation_via_getter() async {
942+
var content = '''
943+
abstract class C {
944+
void Function(int) get f;
945+
int/*?*/ Function() get g;
946+
}
947+
int test(C c) {
948+
c.f(null);
949+
return c.g();
950+
}
951+
''';
952+
var expected = '''
953+
abstract class C {
954+
void Function(int?) get f;
955+
int?/*?*/ Function() get g;
956+
}
957+
int? test(C c) {
958+
c.f(null);
959+
return c.g();
960+
}
961+
''';
962+
await _checkSingleFileChanges(content, expected);
963+
}
964+
941965
test_generic_function_type_syntax_inferred_dynamic_return() async {
942966
var content = '''
943967
abstract class C {

pkg/nnbd_migration/test/edge_builder_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,21 @@ void g(C c, int j) {
15821582
assertEdge(nullable_j.node, never, hard: true));
15831583
}
15841584

1585+
test_methodInvocation_resolves_to_getter() async {
1586+
await analyze('''
1587+
abstract class C {
1588+
int/*1*/ Function(int/*2*/ i) get f;
1589+
}
1590+
int/*3*/ g(C c, int/*4*/ i) => c.f(i);
1591+
''');
1592+
assertEdge(decoratedTypeAnnotation('int/*4*/').node,
1593+
decoratedTypeAnnotation('int/*2*/').node,
1594+
hard: true);
1595+
assertEdge(decoratedTypeAnnotation('int/*1*/').node,
1596+
decoratedTypeAnnotation('int/*3*/').node,
1597+
hard: false);
1598+
}
1599+
15851600
test_methodInvocation_return_type() async {
15861601
await analyze('''
15871602
class C {

0 commit comments

Comments
 (0)