From 028d97bb1dbf8550eeaed668c6cfcfcbff48d854 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Sun, 8 Sep 2019 14:54:39 +0000 Subject: [PATCH] Migration: handle references to already-migrated fields. 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 #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 --- .../lib/src/nullability_migration_impl.dart | 4 +++- pkg/nnbd_migration/lib/src/variables.dart | 4 ++-- pkg/nnbd_migration/test/edge_builder_test.dart | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/nnbd_migration/lib/src/nullability_migration_impl.dart b/pkg/nnbd_migration/lib/src/nullability_migration_impl.dart index 8d9ef948f81a3..53c75ec5bd101 100644 --- a/pkg/nnbd_migration/lib/src/nullability_migration_impl.dart +++ b/pkg/nnbd_migration/lib/src/nullability_migration_impl.dart @@ -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 diff --git a/pkg/nnbd_migration/lib/src/variables.dart b/pkg/nnbd_migration/lib/src/variables.dart index 5ad2e3d0c4168..e1e88ee02db15 100644 --- a/pkg/nnbd_migration/lib/src/variables.dart +++ b/pkg/nnbd_migration/lib/src/variables.dart @@ -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) diff --git a/pkg/nnbd_migration/test/edge_builder_test.dart b/pkg/nnbd_migration/test/edge_builder_test.dart index 8d7529e8b3cb9..ce6e7fceb9ba8 100644 --- a/pkg/nnbd_migration/test/edge_builder_test.dart +++ b/pkg/nnbd_migration/test/edge_builder_test.dart @@ -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) {