Fixed the last unit test that was failing with the new task model
R=scheglov@google.com Review URL: https://codereview.chromium.org//1327363002 .
This commit is contained in:
@@ -10309,6 +10309,12 @@ class RecursiveXmlVisitor_ResolveHtmlTask_internalPerform
|
||||
* used to visit that structure.
|
||||
*/
|
||||
class ResolutionEraser extends GeneralizingAstVisitor<Object> {
|
||||
/**
|
||||
* A flag indicating whether the elements associated with declarations should
|
||||
* be erased.
|
||||
*/
|
||||
bool eraseDeclarations = true;
|
||||
|
||||
@override
|
||||
Object visitAssignmentExpression(AssignmentExpression node) {
|
||||
node.staticElement = null;
|
||||
@@ -10331,13 +10337,17 @@ class ResolutionEraser extends GeneralizingAstVisitor<Object> {
|
||||
|
||||
@override
|
||||
Object visitCompilationUnit(CompilationUnit node) {
|
||||
node.element = null;
|
||||
if (eraseDeclarations) {
|
||||
node.element = null;
|
||||
}
|
||||
return super.visitCompilationUnit(node);
|
||||
}
|
||||
|
||||
@override
|
||||
Object visitConstructorDeclaration(ConstructorDeclaration node) {
|
||||
node.element = null;
|
||||
if (eraseDeclarations) {
|
||||
node.element = null;
|
||||
}
|
||||
return super.visitConstructorDeclaration(node);
|
||||
}
|
||||
|
||||
@@ -10355,7 +10365,9 @@ class ResolutionEraser extends GeneralizingAstVisitor<Object> {
|
||||
|
||||
@override
|
||||
Object visitDirective(Directive node) {
|
||||
node.element = null;
|
||||
if (eraseDeclarations) {
|
||||
node.element = null;
|
||||
}
|
||||
return super.visitDirective(node);
|
||||
}
|
||||
|
||||
@@ -10368,7 +10380,9 @@ class ResolutionEraser extends GeneralizingAstVisitor<Object> {
|
||||
|
||||
@override
|
||||
Object visitFunctionExpression(FunctionExpression node) {
|
||||
node.element = null;
|
||||
if (eraseDeclarations) {
|
||||
node.element = null;
|
||||
}
|
||||
return super.visitFunctionExpression(node);
|
||||
}
|
||||
|
||||
@@ -10415,7 +10429,9 @@ class ResolutionEraser extends GeneralizingAstVisitor<Object> {
|
||||
|
||||
@override
|
||||
Object visitSimpleIdentifier(SimpleIdentifier node) {
|
||||
node.staticElement = null;
|
||||
if (eraseDeclarations || !node.inDeclarationContext()) {
|
||||
node.staticElement = null;
|
||||
}
|
||||
node.propagatedElement = null;
|
||||
return super.visitSimpleIdentifier(node);
|
||||
}
|
||||
@@ -10429,8 +10445,10 @@ class ResolutionEraser extends GeneralizingAstVisitor<Object> {
|
||||
/**
|
||||
* Remove any resolution information from the given AST structure.
|
||||
*/
|
||||
static void erase(AstNode node) {
|
||||
node.accept(new ResolutionEraser());
|
||||
static void erase(AstNode node, {bool eraseDeclarations: true}) {
|
||||
ResolutionEraser eraser = new ResolutionEraser();
|
||||
eraser.eraseDeclarations = eraseDeclarations;
|
||||
node.accept(eraser);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9565,6 +9565,12 @@ class PartialResolverVisitor extends ResolverVisitor {
|
||||
*/
|
||||
final List<VariableElement> staticVariables = <VariableElement>[];
|
||||
|
||||
/**
|
||||
* A flag indicating whether we are currently visiting a child of either a
|
||||
* field or a top-level variable.
|
||||
*/
|
||||
bool inFieldOrTopLevelVariable = false;
|
||||
|
||||
/**
|
||||
* A flag indicating whether we should discard errors while resolving the
|
||||
* initializer for variable declarations. We do this for top-level variables
|
||||
@@ -9600,27 +9606,39 @@ class PartialResolverVisitor extends ResolverVisitor {
|
||||
|
||||
@override
|
||||
Object visitBlockFunctionBody(BlockFunctionBody node) {
|
||||
if (inFieldOrTopLevelVariable) {
|
||||
return super.visitBlockFunctionBody(node);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
|
||||
if (inFieldOrTopLevelVariable) {
|
||||
return super.visitExpressionFunctionBody(node);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Object visitFieldDeclaration(FieldDeclaration node) {
|
||||
if (strongMode && node.isStatic) {
|
||||
_addStaticVariables(node.fields.variables);
|
||||
bool wasDiscarding = discardErrorsInInitializer;
|
||||
discardErrorsInInitializer = true;
|
||||
try {
|
||||
return super.visitFieldDeclaration(node);
|
||||
} finally {
|
||||
discardErrorsInInitializer = wasDiscarding;
|
||||
bool wasInFieldOrTopLevelVariable = inFieldOrTopLevelVariable;
|
||||
try {
|
||||
inFieldOrTopLevelVariable = true;
|
||||
if (strongMode && node.isStatic) {
|
||||
_addStaticVariables(node.fields.variables);
|
||||
bool wasDiscarding = discardErrorsInInitializer;
|
||||
discardErrorsInInitializer = true;
|
||||
try {
|
||||
return super.visitFieldDeclaration(node);
|
||||
} finally {
|
||||
discardErrorsInInitializer = wasDiscarding;
|
||||
}
|
||||
}
|
||||
return super.visitFieldDeclaration(node);
|
||||
} finally {
|
||||
inFieldOrTopLevelVariable = wasInFieldOrTopLevelVariable;
|
||||
}
|
||||
return super.visitFieldDeclaration(node);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -9637,17 +9655,23 @@ class PartialResolverVisitor extends ResolverVisitor {
|
||||
|
||||
@override
|
||||
Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
|
||||
if (strongMode) {
|
||||
_addStaticVariables(node.variables.variables);
|
||||
bool wasDiscarding = discardErrorsInInitializer;
|
||||
discardErrorsInInitializer = true;
|
||||
try {
|
||||
return super.visitTopLevelVariableDeclaration(node);
|
||||
} finally {
|
||||
discardErrorsInInitializer = wasDiscarding;
|
||||
bool wasInFieldOrTopLevelVariable = inFieldOrTopLevelVariable;
|
||||
try {
|
||||
inFieldOrTopLevelVariable = true;
|
||||
if (strongMode) {
|
||||
_addStaticVariables(node.variables.variables);
|
||||
bool wasDiscarding = discardErrorsInInitializer;
|
||||
discardErrorsInInitializer = true;
|
||||
try {
|
||||
return super.visitTopLevelVariableDeclaration(node);
|
||||
} finally {
|
||||
discardErrorsInInitializer = wasDiscarding;
|
||||
}
|
||||
}
|
||||
return super.visitTopLevelVariableDeclaration(node);
|
||||
} finally {
|
||||
inFieldOrTopLevelVariable = wasInFieldOrTopLevelVariable;
|
||||
}
|
||||
return super.visitTopLevelVariableDeclaration(node);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2678,7 +2678,7 @@ class InferStaticVariableTypeTask extends InferStaticVariableTask {
|
||||
"NodeLocator failed to find a variable's declaration");
|
||||
}
|
||||
Expression initializer = declaration.initializer;
|
||||
initializer.accept(new ResolutionEraser());
|
||||
ResolutionEraser.erase(initializer, eraseDeclarations: false);
|
||||
ResolutionContext resolutionContext =
|
||||
ResolutionContextBuilder.contextFor(initializer, errorListener);
|
||||
ResolverVisitor visitor = new ResolverVisitor(
|
||||
|
||||
@@ -102,7 +102,12 @@ class AnalysisDriver {
|
||||
WorkOrder workOrder = createWorkOrderForResult(target, result);
|
||||
if (workOrder != null) {
|
||||
while (workOrder.moveNext()) {
|
||||
// AnalysisTask previousTask = task;
|
||||
// String message = workOrder.current.toString();
|
||||
task = performWorkItem(workOrder.current);
|
||||
// if (task == null) {
|
||||
// throw new AnalysisException(message, previousTask.caughtException);
|
||||
// }
|
||||
}
|
||||
}
|
||||
return task;
|
||||
|
||||
@@ -1911,25 +1911,19 @@ class Z {}
|
||||
|
||||
@reflectiveTest
|
||||
class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest {
|
||||
void fail_perform_nestedDeclarations() {
|
||||
void test_perform_nestedDeclarations() {
|
||||
enableStrongMode();
|
||||
AnalysisTarget source = newSource(
|
||||
'/test.dart',
|
||||
'''
|
||||
var Y = (int x, int y) {
|
||||
var f = (int x) {
|
||||
int squared(int value) => value * value;
|
||||
var xSquared = squared(x);
|
||||
var ySquared = squared(y);
|
||||
return Math.sqrt(xSquared + ySquared);
|
||||
return xSquared;
|
||||
};
|
||||
''');
|
||||
computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6,
|
||||
matcher: isInferStaticVariableTypesInUnitTask);
|
||||
CompilationUnit unit = outputs[RESOLVED_UNIT6];
|
||||
VariableDeclaration variableY = getTopLevelVariable(unit, 'Y');
|
||||
|
||||
InterfaceType intType = context.typeProvider.intType;
|
||||
expect(variableY.initializer.staticType, intType);
|
||||
}
|
||||
|
||||
void test_perform_recursive() {
|
||||
@@ -1970,6 +1964,30 @@ class M {}
|
||||
expect(variableC.element.type, typeM);
|
||||
expect(variableC.initializer.staticType, typeM);
|
||||
}
|
||||
|
||||
void test_perform_simple() {
|
||||
enableStrongMode();
|
||||
AnalysisTarget source = newSource(
|
||||
'/test.dart',
|
||||
'''
|
||||
var X = 1;
|
||||
|
||||
var Y = () {
|
||||
return 1 + X;
|
||||
};
|
||||
''');
|
||||
computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6,
|
||||
matcher: isInferStaticVariableTypesInUnitTask);
|
||||
CompilationUnit unit = outputs[RESOLVED_UNIT6];
|
||||
TopLevelVariableDeclaration declaration = unit.declarations[1];
|
||||
FunctionExpression function =
|
||||
declaration.variables.variables[0].initializer;
|
||||
BlockFunctionBody body = function.body;
|
||||
ReturnStatement statement = body.block.statements[0];
|
||||
Expression expression = statement.expression;
|
||||
InterfaceType intType = context.typeProvider.intType;
|
||||
expect(expression.staticType, intType);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
|
||||
Reference in New Issue
Block a user