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 <scheglov@google.com>
This commit is contained in:
Paul Berry
2019-09-08 14:54:39 +00:00
committed by commit-bot@chromium.org
parent cbe135255d
commit 028d97bb1d
3 changed files with 15 additions and 3 deletions
@@ -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
+2 -2
View File
@@ -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)
@@ -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) {