Skip to content

Commit f2cc27f

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: preliminary support for interface types without type parameters.
I'll build on this in future CLs to address more complex cases, where the type is instantiated to a bound. Fixes #37213. Change-Id: I1e23c5599557ef17177483222f15b1a7985b9ca8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105726 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 68b2d53 commit f2cc27f

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

pkg/nnbd_migration/lib/src/node_builder.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ $stackTrace''');
153153
var namedParameters = const <String, DecoratedType>{};
154154
if (type is InterfaceType && type.typeParameters.isNotEmpty) {
155155
if (node is TypeName) {
156-
assert(node.typeArguments != null);
157-
typeArguments =
158-
node.typeArguments.arguments.map((t) => t.accept(this)).toList();
156+
if (node.typeArguments == null) {
157+
typeArguments =
158+
type.typeArguments.map(_decorateImplicitTypeArgument).toList();
159+
} else {
160+
typeArguments =
161+
node.typeArguments.arguments.map((t) => t.accept(this)).toList();
162+
}
159163
} else {
160164
assert(false); // TODO(paulberry): is this possible?
161165
}
@@ -227,6 +231,16 @@ $stackTrace''');
227231
return _NullabilityComment.none;
228232
}
229233

234+
/// Creates a DecoratedType corresponding to [type], with fresh nullability
235+
/// nodes everywhere that don't correspond to any source location. These
236+
/// nodes can later be unioned with other nodes.
237+
DecoratedType _decorateImplicitTypeArgument(DartType type) {
238+
if (type.isDynamic) {
239+
return DecoratedType(type, _graph.always);
240+
}
241+
throw UnimplementedError('TODO(paulberry): ${type.runtimeType}');
242+
}
243+
230244
/// Common handling of function and method declarations.
231245
void _handleExecutableDeclaration(
232246
ExecutableElement declaredElement,

pkg/nnbd_migration/test/api_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,18 @@ int f(int i) {
645645
await _checkSingleFileChanges(content, expected);
646646
}
647647

648+
test_genericType_noTypeArguments() async {
649+
var content = '''
650+
void f(C c) {}
651+
class C<E> {}
652+
''';
653+
var expected = '''
654+
void f(C c) {}
655+
class C<E> {}
656+
''';
657+
await _checkSingleFileChanges(content, expected);
658+
}
659+
648660
test_getter_topLevel() async {
649661
var content = '''
650662
int get g => 0;

pkg/nnbd_migration/test/migration_visitor_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,19 @@ void f(void Function(int) x) {}
13391339
expect(decoratedIntType.node, isNot(never));
13401340
}
13411341

1342+
test_interfaceType_generic_instantiate_to_dynamic() async {
1343+
await analyze('''
1344+
void f(List x) {}
1345+
''');
1346+
var decoratedListType = decoratedTypeAnnotation('List');
1347+
expect(decoratedFunctionType('f').positionalParameters[0],
1348+
same(decoratedListType));
1349+
expect(decoratedListType.node, isNotNull);
1350+
expect(decoratedListType.node, isNot(never));
1351+
var decoratedArgType = decoratedListType.typeArguments[0];
1352+
expect(decoratedArgType.node, same(always));
1353+
}
1354+
13421355
test_interfaceType_typeParameter() async {
13431356
await analyze('''
13441357
void f(List<int> x) {}

0 commit comments

Comments
 (0)