Skip to content

Commit 8938a5e

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: make an edge origin for assignments of dynamic.
Change-Id: I75d037aa7ee890488a92e113f58094b5733a9b8f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125004 Reviewed-by: Mike Fairhurst <mfairhurst@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent c9ef7cc commit 8938a5e

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

pkg/nnbd_migration/lib/instrumentation.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ enum EdgeOriginKind {
128128
alwaysNullableType,
129129
compoundAssignment,
130130
defaultValue,
131+
dynamicAssignment,
131132
expressionChecks,
132133
fieldFormalParameter,
133134
forEachVariable,

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,9 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
16261626
'(${expression.toSource()}) offset=${expression.offset}');
16271627
}
16281628
EdgeOrigin edgeOrigin;
1629-
if (!sourceType.type.isDynamic) {
1629+
if (sourceType.type.isDynamic) {
1630+
edgeOrigin = DynamicAssignmentOrigin(source, expression);
1631+
} else {
16301632
if (fromDefaultValue) {
16311633
edgeOrigin = DefaultValueOrigin(source, expression);
16321634
} else {

pkg/nnbd_migration/lib/src/edge_origin.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ class DefaultValueOrigin extends EdgeOrigin {
7070
EdgeOriginKind get kind => EdgeOriginKind.defaultValue;
7171
}
7272

73+
/// An edge origin used for edges that originated because of an assignment
74+
/// involving a value with a dynamic type.
75+
class DynamicAssignmentOrigin extends EdgeOrigin {
76+
DynamicAssignmentOrigin(Source source, AstNode node) : super(source, node);
77+
78+
@override
79+
EdgeOriginKind get kind => EdgeOriginKind.dynamicAssignment;
80+
}
81+
7382
/// Common interface for classes providing information about how an edge came
7483
/// to be; that is, what was found in the source code that led the migration
7584
/// tool to create the edge.

pkg/nnbd_migration/test/instrumentation_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@ int f(int x) => x;
407407
expect(origin.node, findNode.simple('x;'));
408408
}
409409

410+
test_graphEdge_origin_dynamic_assignment() async {
411+
await analyze('''
412+
int f(dynamic x) => x;
413+
''');
414+
var xNode = explicitTypeNullability[findNode.typeAnnotation('dynamic x')];
415+
var returnNode = explicitTypeNullability[findNode.typeAnnotation('int f')];
416+
var matchingEdges = edges
417+
.where((e) => e.sourceNode == xNode && e.destinationNode == returnNode)
418+
.toList();
419+
var origin = edgeOrigin[matchingEdges.single];
420+
expect(origin.kind, EdgeOriginKind.dynamicAssignment);
421+
expect(origin.source, source);
422+
expect(origin.node, findNode.simple('x;'));
423+
}
424+
410425
test_graphEdge_soft() async {
411426
await analyze('''
412427
int f(int x, bool b) {

0 commit comments

Comments
 (0)