Fix summarization of closures in toplevel variable declarations in part files.

We were forgetting to include the unitNum, so it was defaulting to zero,
which worked for non-part files but not for part files.

R=scheglov@google.com

Review URL: https://codereview.chromium.org/2416863003 .
This commit is contained in:
Paul Berry 2016-10-13 13:29:06 -07:00
parent 1ee954029d
commit 809c80fa49
2 changed files with 22 additions and 8 deletions

View file

@ -1216,14 +1216,19 @@ class CompilationUnitElementInBuildUnit extends CompilationUnitElementForLink {
// TODO(paulberry): implement other cases as necessary
throw new UnimplementedError('${element._unlinkedExecutable.kind}');
}
return addRawReference(element.name,
numTypeParameters: element.typeParameters.length,
containingReference:
enclosingClass != null ? addReference(enclosingClass) : null,
dependency: enclosingClass != null
? null
: library.addDependency(element.library as LibraryElementForLink),
kind: kind);
if (enclosingClass == null) {
return addRawReference(element.name,
numTypeParameters: element.typeParameters.length,
dependency:
library.addDependency(element.library as LibraryElementForLink),
unitNum: element.compilationUnit.unitNum,
kind: kind);
} else {
return addRawReference(element.name,
numTypeParameters: element.typeParameters.length,
containingReference: addReference(enclosingClass),
kind: kind);
}
} else if (element is FunctionElementForLink_Initializer) {
return addRawReference('',
containingReference: addReference(element.enclosingElement),
@ -1231,6 +1236,7 @@ class CompilationUnitElementInBuildUnit extends CompilationUnitElementForLink {
} else if (element is TopLevelVariableElementForLink) {
return addRawReference(element.name,
dependency: library.addDependency(element.library),
unitNum: element.compilationUnit.unitNum,
kind: ReferenceKind.topLevelPropertyAccessor);
} else if (element is FieldElementForLink_ClassField) {
ClassElementForLink_Class enclosingClass = element.enclosingElement;

View file

@ -1635,6 +1635,14 @@ f() {
''');
}
test_closure_in_variable_declaration_in_part() {
addSource('/a.dart', 'part of lib; final f = (int i) => i.toDouble();');
checkLibrary('''
library lib;
part "a.dart";
''');
}
test_const_invalid_field_const() {
variablesWithNotConstInitializers.add('f');
checkLibrary(