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