Skip to content

Commit

Permalink
Migration: add support for metadata on library/import/export/part/par…
Browse files Browse the repository at this point in the history
…t-of directives.

Part-of support needed to be added.

Should address ~12 exceptions whose stack trace contains the line:

AnnotationTracker.visitCompilationUnit.<anonymous closure> (package:nnbd_migration/src/utilities/annotation_tracker.dart:39:16)

Change-Id: Ib25d6dc123ac6134b6b5d25081ad5cebe02fd951
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116441
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Sep 10, 2019
1 parent 1daf84f commit f1f709e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/nnbd_migration/lib/src/edge_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,8 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>

@override
DecoratedType visitLibraryDirective(LibraryDirective node) {
// skip directives
// skip directives, but not their metadata
node.metadata.accept(this);
return null;
}

Expand Down Expand Up @@ -924,7 +925,8 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>

@override
DecoratedType visitNamespaceDirective(NamespaceDirective node) {
// skip directives
// skip directives, but not their metadata
node.metadata.accept(this);
return null;
}

Expand All @@ -938,6 +940,13 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
return node.expression.accept(this);
}

@override
DecoratedType visitPartOfDirective(PartOfDirective node) {
// skip directives, but not their metadata
node.metadata.accept(this);
return null;
}

@override
DecoratedType visitPostfixExpression(PostfixExpression node) {
var operatorType = node.operator.type;
Expand Down
83 changes: 83 additions & 0 deletions pkg/nnbd_migration/test/edge_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,15 @@ double f() {
assertNoUpstreamNullability(decoratedTypeAnnotation('double').node);
}

test_export_metadata() async {
await analyze('''
@deprecated
export 'dart:async';
''');
// No assertions needed; the AnnotationTracker mixin verifies that the
// metadata was visited.
}

test_field_metadata() async {
await analyze('''
class A {
Expand Down Expand Up @@ -2250,6 +2259,15 @@ int f(bool b, int i) {
assertEdge(nullable_i, nullable_return, hard: false));
}

test_import_metadata() async {
await analyze('''
@deprecated
import 'dart:async';
''');
// No assertions needed; the AnnotationTracker mixin verifies that the
// metadata was visited.
}

test_indexExpression_dynamic() async {
await analyze('''
int f(dynamic d, int i) {
Expand Down Expand Up @@ -2491,6 +2509,15 @@ bool f(a) => a is List<int>;
assertNoUpstreamNullability(decoratedTypeAnnotation('bool').node);
}

test_library_metadata() async {
await analyze('''
@deprecated
library foo;
''');
// No assertions needed; the AnnotationTracker mixin verifies that the
// metadata was visited.
}

test_libraryDirective() async {
await analyze('''
library foo;
Expand Down Expand Up @@ -3187,6 +3214,62 @@ int f() {
assertEdge(always, decoratedTypeAnnotation('int').node, hard: false));
}

test_part_metadata() async {
var pathContext = resourceProvider.pathContext;
addSource(pathContext.join(pathContext.dirname(testFile), 'part.dart'), '''
part of test;
''');
await analyze('''
library test;
@deprecated
part 'part.dart';
''');
// No assertions needed; the AnnotationTracker mixin verifies that the
// metadata was visited.
}

test_part_of_identifier() async {
var pathContext = resourceProvider.pathContext;
var testFileName = pathContext.basename(testFile);
addSource(pathContext.join(pathContext.dirname(testFile), 'lib.dart'), '''
library test;
part '$testFileName';
''');
await analyze('''
part of test;
''');
// No assertions needed; the AnnotationTracker mixin verifies that the
// metadata was visited.
}

test_part_of_metadata() async {
var pathContext = resourceProvider.pathContext;
var testFileName = pathContext.basename(testFile);
addSource(pathContext.join(pathContext.dirname(testFile), 'lib.dart'), '''
library test;
part '$testFileName';
''');
await analyze('''
@deprecated
part of test;
''');
// No assertions needed; the AnnotationTracker mixin verifies that the
// metadata was visited.
}

test_part_of_path() async {
var pathContext = resourceProvider.pathContext;
var testFileName = pathContext.basename(testFile);
addSource(pathContext.join(pathContext.dirname(testFile), 'lib.dart'), '''
part '$testFileName';
''');
await analyze('''
part of 'lib.dart';
''');
// No assertions needed; the AnnotationTracker mixin verifies that the
// metadata was visited.
}

test_postDominators_assert() async {
await analyze('''
void test(bool b1, bool b2, bool b3, bool _b) {
Expand Down

0 comments on commit f1f709e

Please sign in to comment.