Add support for is expressions
Change-Id: I3be70d83b03a4d00a68070fb03ba2ab989880a9e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106161
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
diff --git a/pkg/nnbd_migration/lib/src/graph_builder.dart b/pkg/nnbd_migration/lib/src/graph_builder.dart
index 80160c2..401f33f 100644
--- a/pkg/nnbd_migration/lib/src/graph_builder.dart
+++ b/pkg/nnbd_migration/lib/src/graph_builder.dart
@@ -392,7 +392,16 @@
@override
DecoratedType visitIsExpression(IsExpression node) {
- throw new UnimplementedError('TODO(brianwilkerson)');
+ var type = node.type;
+ if (type is NamedType && type.typeArguments != null) {
+ // TODO(brianwilkerson) Figure out what constraints we need to add to
+ // allow the tool to decide whether to make the type arguments nullable.
+ throw new UnimplementedError('TODO(brianwilkerson)');
+ } else if (type is GenericFunctionType) {
+ throw new UnimplementedError('TODO(brianwilkerson)');
+ }
+ node.visitChildren(this);
+ return DecoratedType(node.staticType, _graph.never);
}
@override
diff --git a/pkg/nnbd_migration/test/migration_visitor_test.dart b/pkg/nnbd_migration/test/migration_visitor_test.dart
index e44e273..c156218 100644
--- a/pkg/nnbd_migration/test/migration_visitor_test.dart
+++ b/pkg/nnbd_migration/test/migration_visitor_test.dart
@@ -851,6 +851,29 @@
assertNoUpstreamNullability(decoratedTypeAnnotation('int').node);
}
+ @failingTest
+ test_isExpression_genericFunctionType() async {
+ await analyze('''
+bool f(a) => a is int Function(String);
+''');
+ assertNoUpstreamNullability(decoratedTypeAnnotation('bool').node);
+ }
+
+ test_isExpression_typeName_noTypeArguments() async {
+ await analyze('''
+bool f(a) => a is String;
+''');
+ assertNoUpstreamNullability(decoratedTypeAnnotation('bool').node);
+ }
+
+ @failingTest
+ test_isExpression_typeName_typeArguments() async {
+ await analyze('''
+bool f(a) => a is List<int>;
+''');
+ assertNoUpstreamNullability(decoratedTypeAnnotation('bool').node);
+ }
+
test_methodDeclaration_resets_unconditional_control_flow() async {
await analyze('''
class C {