Skip to content

Commit

Permalink
Migration: handle references to already-migrated fields.
Browse files Browse the repository at this point in the history
This should address ~54 exceptions having this line in the stack trace:

Variables._createDecoratedElementType (package:nnbd_migration/src/variables.dart:241:7)

Note: this change exposed issue flutter#38257, so it includes a workaround for it.
Change-Id: Id533c070a02d310661a05035679d9476ad2ab240
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116220
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Sep 8, 2019
1 parent cbe1352 commit 028d97b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/nnbd_migration/lib/src/nullability_migration_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class NullabilityMigrationImpl implements NullabilityMigration {
void finish() {
_graph.propagate();
if (_graph.unsatisfiedSubstitutions.isNotEmpty) {
throw new UnimplementedError('Need to report unsatisfied substitutions');
// TODO(paulberry): for now we just ignore unsatisfied substitutions, to
// work around https://github.com/dart-lang/sdk/issues/38257
// throw new UnimplementedError('Need to report unsatisfied substitutions');
}
// TODO(paulberry): it would be nice to report on unsatisfied edges as well,
// however, since every `!` we add has an unsatisfied edge associated with
Expand Down
4 changes: 2 additions & 2 deletions pkg/nnbd_migration/lib/src/variables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ class Variables implements VariableRecorder, VariableRepository {
}

DecoratedType decoratedType;
if (element is ExecutableElement) {
if (element is FunctionTypedElement) {
decoratedType = _alreadyMigratedCodeDecorator.decorate(element.type);
} else if (element is TopLevelVariableElement) {
} else if (element is VariableElement) {
decoratedType = _alreadyMigratedCodeDecorator.decorate(element.type);
} else {
// TODO(paulberry)
Expand Down
10 changes: 10 additions & 0 deletions pkg/nnbd_migration/test/edge_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ class EdgeBuilderTest extends EdgeBuilderTestBase {
return variables.decoratedExpressionType(findNode.expression(text));
}

test_already_migrated_field() async {
await analyze('''
double f() => double.NAN;
''');
var nanElement = typeProvider.doubleType.element.getField('NAN');
assertEdge(variables.decoratedElementType(nanElement).node,
decoratedTypeAnnotation('double f').node,
hard: false);
}

test_assert_demonstrates_non_null_intent() async {
await analyze('''
void f(int i) {
Expand Down

0 comments on commit 028d97b

Please sign in to comment.