Skip to content

Commit bad1816

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: add edge builder support for generic method invocations.
This should address ~25 exceptions whose stack trace includes the line: EdgeBuilder.visitMethodDeclaration (package:nnbd_migration/src/edge_builder.dart:843:7) Change-Id: I0076592f43f18c68f499fc9a80347a73033f8919 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115802 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 35f45f0 commit bad1816

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,6 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
839839

840840
@override
841841
DecoratedType visitMethodDeclaration(MethodDeclaration node) {
842-
if (node.typeParameters != null) {
843-
_unimplemented(node, 'Generic method');
844-
}
845842
_handleExecutableDeclaration(node, node.declaredElement, node.metadata,
846843
node.returnType, node.parameters, null, node.body, null);
847844
return null;

pkg/nnbd_migration/test/edge_builder_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,29 @@ int/*2*/ g() {
17491749
hard: false));
17501750
}
17511751

1752+
test_genericMethodInvocation() async {
1753+
await analyze('''
1754+
class Base {
1755+
T foo<T>(T x) => x;
1756+
}
1757+
class Derived extends Base {}
1758+
int bar(Derived d, int i) => d.foo(i);
1759+
''');
1760+
var implicitTypeArgumentMatcher = anyNode;
1761+
assertEdge(
1762+
decoratedTypeAnnotation('int i').node,
1763+
substitutionNode(
1764+
implicitTypeArgumentMatcher, decoratedTypeAnnotation('T x').node),
1765+
hard: true);
1766+
var implicitTypeArgumentNullability =
1767+
implicitTypeArgumentMatcher.matchingNode;
1768+
assertEdge(
1769+
substitutionNode(implicitTypeArgumentNullability,
1770+
decoratedTypeAnnotation('T foo').node),
1771+
decoratedTypeAnnotation('int bar').node,
1772+
hard: false);
1773+
}
1774+
17521775
test_if_condition() async {
17531776
await analyze('''
17541777
void f(bool b) {

pkg/nnbd_migration/test/migration_visitor_test_base.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ import 'package:test/test.dart';
2121

2222
import 'abstract_single_unit.dart';
2323

24+
/// A [NodeMatcher] that matches any node, and records what node it matched to.
25+
class AnyNodeMatcher implements NodeMatcher {
26+
final List<NullabilityNode> _matchingNodes = [];
27+
28+
NullabilityNode get matchingNode => _matchingNodes.single;
29+
30+
@override
31+
bool matches(NullabilityNode node) {
32+
_matchingNodes.add(node);
33+
return true;
34+
}
35+
}
36+
2437
/// Mixin allowing unit tests to create decorated types easily.
2538
mixin DecoratedTypeTester implements DecoratedTypeTesterBase {
2639
int _offset = 0;
@@ -114,7 +127,7 @@ class EdgeBuilderTestBase extends MigrationVisitorTestBase {
114127
/// Mixin allowing unit tests to check for the presence of graph edges.
115128
mixin EdgeTester {
116129
/// Returns a [NodeMatcher] that matches any node whatsoever.
117-
NodeMatcher get anyNode => const _AnyNodeMatcher();
130+
AnyNodeMatcher get anyNode => AnyNodeMatcher();
118131

119132
NullabilityGraphForTesting get graph;
120133

@@ -337,14 +350,6 @@ abstract class NodeMatcher {
337350
bool matches(NullabilityNode node);
338351
}
339352

340-
/// A [NodeMatcher] that matches any node.
341-
class _AnyNodeMatcher implements NodeMatcher {
342-
const _AnyNodeMatcher();
343-
344-
@override
345-
bool matches(NullabilityNode node) => true;
346-
}
347-
348353
/// A [NodeMatcher] that matches exactly one node.
349354
class _ExactNodeMatcher implements NodeMatcher {
350355
final NullabilityNode _expectation;

0 commit comments

Comments
 (0)