Skip to content

Commit

Permalink
NNBD migrator: record type information in TypeName type arguments
Browse files Browse the repository at this point in the history
This prevents the following crash:

Bad state: Missing declarated type annotation in /home/test/lib/test.dart; for Object
  package:nnbd_migration/src/variables.dart 68:7                      Variables.decoratedTypeAnnotation
  package:nnbd_migration/src/edge_builder.dart 1378:26                EdgeBuilder.visitTypeName
  package:analyzer/src/dart/ast/ast.dart 10012:49                     TypeNameImpl.accept
  package:nnbd_migration/src/edge_builder.dart 844:10                 EdgeBuilder.visitIsExpression
  package:analyzer/src/dart/ast/ast.dart 6372:49                      IsExpressionImpl.accept

Change-Id: I23ed49ccbd3625d9f9fbc7e07a69be3c580896ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127457
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
  • Loading branch information
srawlins authored and commit-bot@chromium.org committed Dec 9, 2019
1 parent a17884a commit 1aeff32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/nnbd_migration/lib/src/node_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
try {
node.typeParameters?.accept(this);
node.parameters?.accept(this);
// Node: we don't pass _typeFormalBounds into DecoratedType because we're
// Note: we don't pass _typeFormalBounds into DecoratedType because we're
// not defining a generic function type, we're defining a generic typedef
// of an ordinary (non-generic) function type.
decoratedFunctionType = DecoratedType(functionType, _graph.never,
Expand Down Expand Up @@ -398,6 +398,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
}
DecoratedType decoratedType;
if (type is FunctionType && node is! GenericFunctionType) {
(node as TypeName).typeArguments?.accept(this);
// node is a reference to a typedef. Treat it like an inferred type (we
// synthesize new nodes for it). These nodes will be unioned with the
// typedef nodes by the edge builder.
Expand Down
18 changes: 18 additions & 0 deletions pkg/nnbd_migration/test/edge_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,15 @@ int/*2*/ g() {
hard: false));
}

test_functionTypeAlias_inExpression() async {
await analyze('''
typedef bool _P<T>(T value);
bool f(Object x) => x is _P<Object>;
''');
// No assertions here; just don't crash. This test can be repurposed for
// a more specific test with assertions.
}

test_genericMethodInvocation() async {
await analyze('''
class Base {
Expand Down Expand Up @@ -2400,6 +2409,15 @@ int bar(Derived<String> d, int i, List<String> j) => d.foo(i, j);
hard: false);
}

test_genericTypeAlias_inExpression() async {
await analyze('''
typedef _P<T> = bool Function(T value);
bool f(Object x) => x is _P<Object>;
''');
// No assertions here; just don't crash. This test can be repurposed for
// a more specific test with assertions.
}

test_if_condition() async {
await analyze('''
void f(bool b) {
Expand Down

0 comments on commit 1aeff32

Please sign in to comment.