Migration: implement Variables._decorateDirectSupertypes.

Change-Id: I0e35bf57628bcb72525577e646d6c5de168712bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113844
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry
2019-08-20 20:42:09 +00:00
committed by commit-bot@chromium.org
parent d67eaefe77
commit 3fe9ba152f
2 changed files with 31 additions and 7 deletions
+12 -7
View File
@@ -4,6 +4,7 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/element/handle.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/generated/source.dart';
@@ -245,14 +246,18 @@ class Variables implements VariableRecorder, VariableRepository {
/// class.
Map<ClassElement, DecoratedType> _decorateDirectSupertypes(
ClassElement class_) {
if (class_.type.isObject) {
// TODO(paulberry): this special case is just to get the basic
// infrastructure working (necessary since all classes derive from
// Object). Once we have the full implementation this case shouldn't be
// needed.
return const {};
var result = <ClassElement, DecoratedType>{};
for (var supertype in class_.allSupertypes) {
var decoratedSupertype =
_alreadyMigratedCodeDecorator.decorate(supertype);
assert(identical(decoratedSupertype.node, _graph.never));
var class_ = (decoratedSupertype.type as InterfaceType).element;
if (class_ is ClassElementHandle) {
class_ = (class_ as ClassElementHandle).actualElement;
}
result[class_] = decoratedSupertype;
}
throw UnimplementedError('TODO(paulberry)');
return result;
}
int _uniqueOffsetForTypeAnnotation(TypeAnnotation typeAnnotation) =>
@@ -410,6 +410,25 @@ class C<T extends List<int>> {
hard: false);
}
test_assign_upcast_generic() async {
await analyze('''
void f(Iterable<int> x) {}
void g(List<int> x) {
f(x);
}
''');
var iterableInt = decoratedTypeAnnotation('Iterable<int>');
var listInt = decoratedTypeAnnotation('List<int>');
assertEdge(listInt.node, iterableInt.node, hard: true);
var substitution = graph
.getUpstreamEdges(iterableInt.typeArguments[0].node)
.single
.primarySource as NullabilityNodeForSubstitution;
expect(substitution.innerNode, same(listInt.typeArguments[0].node));
expect(substitution.outerNode, same(never));
}
test_assignmentExpression_field() async {
await analyze('''
class C {