Skip to content

Commit e9fdeb2

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: add support for creating instances without supplying type arguments.
Should address ~622 exceptions whose stack trace contains the line: new DecoratedType.<anonymous closure> (package:nnbd_migration/src/decorated_type.dart:64:16) Change-Id: I01951abf28b7c474ca31eb2d2878caaf3c3b9073 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114744 Reviewed-by: Dan Rubel <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 66e349d commit e9fdeb2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,15 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
758758
.map((t) => _variables.decoratedTypeAnnotation(source, t))
759759
.toList();
760760
} else {
761-
decoratedTypeArguments = const [];
761+
var staticType = node.staticType;
762+
if (staticType is InterfaceType) {
763+
decoratedTypeArguments = staticType.typeArguments
764+
.map((t) => DecoratedType.forImplicitType(_typeProvider, t, _graph))
765+
.toList();
766+
} else {
767+
// Note: this could happen if the code being migrated has errors.
768+
decoratedTypeArguments = const [];
769+
}
762770
}
763771
var createdType = DecoratedType(node.staticType, _graph.never,
764772
typeArguments: decoratedTypeArguments);
@@ -1666,6 +1674,9 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
16661674
DecoratedType.forImplicitType(_typeProvider, argType, _graph))
16671675
.toList();
16681676
calleeType = calleeType.instantiate(argumentTypes);
1677+
} else if (constructorTypeParameters != null) {
1678+
// No need to instantiate; caller has already substituted in the
1679+
// correct type arguments.
16691680
} else {
16701681
assert(
16711682
false,

pkg/nnbd_migration/test/edge_builder_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,23 @@ C<Object> f() => C<dynamic>();
19691969
hard: false);
19701970
}
19711971

1972+
test_instanceCreation_generic_inferredParameterType() async {
1973+
await analyze('''
1974+
class C<T> {
1975+
C(List<T> x);
1976+
}
1977+
C<int> f(List<int> x) => C(x);
1978+
''');
1979+
var edge = assertEdge(anyNode, decoratedTypeAnnotation('int> f').node,
1980+
hard: false);
1981+
var inferredTypeArgument = edge.primarySource;
1982+
assertEdge(
1983+
decoratedTypeAnnotation('int> x').node,
1984+
substitutionNode(
1985+
inferredTypeArgument, decoratedTypeAnnotation('T> x').node),
1986+
hard: false);
1987+
}
1988+
19721989
test_instanceCreation_generic_parameter() async {
19731990
await analyze('''
19741991
class C<T> {

0 commit comments

Comments
 (0)