Skip to content

Commit

Permalink
Migration: add support for reads from fields.
Browse files Browse the repository at this point in the history
Change-Id: Iaa74a0d5d730df0a5ad57de839de01f1b54c1240
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/104807
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Jun 5, 2019
1 parent 2cd8603 commit 42688f9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
19 changes: 17 additions & 2 deletions pkg/analysis_server/lib/src/nullability/graph_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,23 @@ class GraphBuilder extends GeneralizingAstVisitor<DecoratedType> {
} else {
baseElement = element;
}
var decoratedBaseType =
_variables.decoratedElementType(baseElement, create: true);
DecoratedType decoratedBaseType;
if (baseElement is PropertyAccessorElement &&
baseElement.isSynthetic &&
!baseElement.variable.isSynthetic) {
var variable = baseElement.variable;
if (baseElement.isGetter) {
decoratedBaseType = DecoratedType(
baseElement.type, NullabilityNode.never,
returnType:
_variables.decoratedElementType(variable, create: true));
} else {
throw UnimplementedError('TODO(paulberry)');
}
} else {
decoratedBaseType =
_variables.decoratedElementType(baseElement, create: true);
}
if (substitution != null) {
DartType elementType;
if (element is MethodElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,19 @@ int f() {
contextNode: decoratedTypeAnnotation('int').node);
}

test_prefixedIdentifier_return_type() async {
test_prefixedIdentifier_field_type() async {
await analyze('''
class C {
bool b = true;
}
bool f(C c) => c.b;
''');
assertEdge(decoratedTypeAnnotation('bool b').node,
decoratedTypeAnnotation('bool f').node,
hard: false);
}

test_prefixedIdentifier_getter_type() async {
await analyze('''
class C {
bool get b => true;
Expand Down Expand Up @@ -986,6 +998,20 @@ class NodeBuilderTest extends MigrationVisitorTestBase {
DecoratedType decoratedTypeParameterBound(String search) => _variables
.decoratedElementType(findNode.typeParameter(search).declaredElement);

test_field_type_simple() async {
await analyze('''
class C {
int f = 0;
}
''');
var decoratedType = decoratedTypeAnnotation('int');
expect(decoratedType.node, TypeMatcher<NullabilityNodeMutable>());
expect(
_variables.decoratedElementType(
findNode.fieldDeclaration('f').fields.variables[0].declaredElement),
same(decoratedType));
}

test_interfaceType_typeParameter() async {
await analyze('''
void f(List<int> x) {}
Expand Down
16 changes: 16 additions & 0 deletions pkg/analysis_server/test/src/nullability/provisional_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ void main() {
await _checkSingleFileChanges(content, expected);
}

test_data_flow_field_read() async {
var content = '''
class C {
int/*?*/ f = 0;
}
int f(C c) => c.f;
''';
var expected = '''
class C {
int?/*?*/ f = 0;
}
int? f(C c) => c.f;
''';
await _checkSingleFileChanges(content, expected);
}

test_data_flow_generic_inward() async {
var content = '''
class C<T> {
Expand Down

0 comments on commit 42688f9

Please sign in to comment.