Skip to content

Commit

Permalink
Migration: Handle uses of typedef types as expressions.
Browse files Browse the repository at this point in the history
Addresses ~44 exceptions whose stack trace contains the line:

EdgeBuilder.visitSimpleIdentifier (package:nnbd_migration/src/edge_builder.dart:1123:7)

Change-Id: I5c76b7478d15d2338d7b47cbc6bebcf8c0d2d739
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116245
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Sep 8, 2019
1 parent 0b0c113 commit 4a4f7cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/nnbd_migration/lib/src/edge_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
return staticElement.isGetter
? elementType.returnType
: elementType.positionalParameters[0];
} else if (staticElement is ClassElement) {
} else if (staticElement is TypeDefiningElement) {
return _nonNullableTypeType;
} else {
// TODO(paulberry)
Expand Down
36 changes: 34 additions & 2 deletions pkg/nnbd_migration/test/edge_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4505,7 +4505,15 @@ void f(List<int> x) {}
hard: true);
}

test_typeName() async {
test_typeName_class() async {
await analyze('''
class C {}
Type f() => C;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('Type').node);
}

test_typeName_from_sdk() async {
await analyze('''
Type f() {
return int;
Expand All @@ -4514,14 +4522,38 @@ Type f() {
assertNoUpstreamNullability(decoratedTypeAnnotation('Type').node);
}

test_typeName_prefixed() async {
test_typeName_from_sdk_prefixed() async {
await analyze('''
import 'dart:async' as a;
Type f() => a.Future;
''');
assertEdge(never, decoratedTypeAnnotation('Type').node, hard: false);
}

test_typeName_functionTypeAlias() async {
await analyze('''
typedef void F();
Type f() => F;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('Type').node);
}

test_typeName_genericTypeAlias() async {
await analyze('''
typedef F = void Function();
Type f() => F;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('Type').node);
}

test_typeName_mixin() async {
await analyze('''
mixin M {}
Type f() => M;
''');
assertNoUpstreamNullability(decoratedTypeAnnotation('Type').node);
}

test_typeName_union_with_bound() async {
await analyze('''
class C<T extends Object> {}
Expand Down

0 comments on commit 4a4f7cb

Please sign in to comment.