Skip to content

Commit 1aeff32

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
NNBD migrator: record type information in TypeName type arguments
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>
1 parent a17884a commit 1aeff32

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pkg/nnbd_migration/lib/src/node_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
253253
try {
254254
node.typeParameters?.accept(this);
255255
node.parameters?.accept(this);
256-
// Node: we don't pass _typeFormalBounds into DecoratedType because we're
256+
// Note: we don't pass _typeFormalBounds into DecoratedType because we're
257257
// not defining a generic function type, we're defining a generic typedef
258258
// of an ordinary (non-generic) function type.
259259
decoratedFunctionType = DecoratedType(functionType, _graph.never,
@@ -398,6 +398,7 @@ class NodeBuilder extends GeneralizingAstVisitor<DecoratedType>
398398
}
399399
DecoratedType decoratedType;
400400
if (type is FunctionType && node is! GenericFunctionType) {
401+
(node as TypeName).typeArguments?.accept(this);
401402
// node is a reference to a typedef. Treat it like an inferred type (we
402403
// synthesize new nodes for it). These nodes will be unioned with the
403404
// typedef nodes by the edge builder.

pkg/nnbd_migration/test/edge_builder_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,15 @@ int/*2*/ g() {
23322332
hard: false));
23332333
}
23342334

2335+
test_functionTypeAlias_inExpression() async {
2336+
await analyze('''
2337+
typedef bool _P<T>(T value);
2338+
bool f(Object x) => x is _P<Object>;
2339+
''');
2340+
// No assertions here; just don't crash. This test can be repurposed for
2341+
// a more specific test with assertions.
2342+
}
2343+
23352344
test_genericMethodInvocation() async {
23362345
await analyze('''
23372346
class Base {
@@ -2400,6 +2409,15 @@ int bar(Derived<String> d, int i, List<String> j) => d.foo(i, j);
24002409
hard: false);
24012410
}
24022411

2412+
test_genericTypeAlias_inExpression() async {
2413+
await analyze('''
2414+
typedef _P<T> = bool Function(T value);
2415+
bool f(Object x) => x is _P<Object>;
2416+
''');
2417+
// No assertions here; just don't crash. This test can be repurposed for
2418+
// a more specific test with assertions.
2419+
}
2420+
24032421
test_if_condition() async {
24042422
await analyze('''
24052423
void f(bool b) {

0 commit comments

Comments
 (0)