mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:17:55 +00:00
Fix for inference when AssignmentExpression references a not yet inferred variable.
Change-Id: I61b57429607454d4cfe002fe6588858853a166dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162560 Reviewed-by: Mike Fairhurst <mfairhurst@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
ec65869de7
commit
54e98b03d7
|
@ -6967,21 +6967,7 @@ class PropertyAccessorElementImpl_ImplicitGetter
|
|||
}
|
||||
|
||||
@override
|
||||
DartType get returnTypeInternal {
|
||||
var returnType = variable.type;
|
||||
|
||||
// While performing inference during linking, the first step is to collect
|
||||
// dependencies. During this step we resolve the expression, but we might
|
||||
// reference elements that don't have their types inferred yet. So, here
|
||||
// we give some type. A better solution would be to infer recursively, but
|
||||
// we are not doing this yet.
|
||||
if (returnType == null) {
|
||||
assert(linkedContext.isLinking);
|
||||
return DynamicTypeImpl.instance;
|
||||
}
|
||||
|
||||
return returnType;
|
||||
}
|
||||
DartType get returnTypeInternal => variable.type;
|
||||
|
||||
@override
|
||||
FunctionType get type => ElementTypeProvider.current.getExecutableType(this);
|
||||
|
@ -7138,7 +7124,19 @@ abstract class PropertyInducingElementImpl
|
|||
DartType get typeInternal {
|
||||
if (linkedNode != null) {
|
||||
if (_type != null) return _type;
|
||||
return _type = linkedContext.getType(linkedNode);
|
||||
_type = linkedContext.getType(linkedNode);
|
||||
|
||||
// While performing inference during linking, the first step is to collect
|
||||
// dependencies. During this step we resolve the expression, but we might
|
||||
// reference elements that don't have their types inferred yet. So, here
|
||||
// we give some type. A better solution would be to infer recursively, but
|
||||
// we are not doing this yet.
|
||||
if (_type == null) {
|
||||
assert(linkedContext.isLinking);
|
||||
return DynamicTypeImpl.instance;
|
||||
}
|
||||
|
||||
return _type;
|
||||
}
|
||||
if (isSynthetic && _type == null) {
|
||||
if (getter != null) {
|
||||
|
|
|
@ -10335,6 +10335,20 @@ dynamic d;
|
|||
''');
|
||||
}
|
||||
|
||||
test_type_inference_assignmentExpression_references_onTopLevelVariable() async {
|
||||
var library = await checkLibrary('''
|
||||
var a = () {
|
||||
b += 0;
|
||||
return 0;
|
||||
};
|
||||
var b = 0;
|
||||
''');
|
||||
checkElementText(library, '''
|
||||
int Function() a;
|
||||
int b;
|
||||
''');
|
||||
}
|
||||
|
||||
test_type_inference_based_on_loadLibrary() async {
|
||||
addLibrarySource('/a.dart', '');
|
||||
var library = await checkLibrary('''
|
||||
|
|
Loading…
Reference in a new issue