Commit 893d7c8d authored by Heinz Wiesinger's avatar Heinz Wiesinger

Fix uses of function call parameters after closures

parent 54964af0
......@@ -492,6 +492,13 @@ void ContextBuilder::visitUnaryExpression(UnaryExpressionAst* node)
}
}
void ContextBuilder::visitFunctionCallParameterListElement(FunctionCallParameterListElementAst* node)
{
DefaultVisitor::visitFunctionCallParameterListElement(node);
setContextOnNode(node, currentContext());
}
void ContextBuilder::reportError(const QString& errorMsg, AstNode* node, IProblem::Severity severity)
{
reportError(errorMsg, m_editor->findRange(node), severity);
......
......@@ -84,6 +84,8 @@ protected:
void visitFunctionDeclarationStatement(FunctionDeclarationStatementAst* node) override;
void visitClosure(ClosureAst* node) override;
void visitUnaryExpression(UnaryExpressionAst* node) override;
void visitFunctionCallParameterListElement(FunctionCallParameterListElementAst* node) override;
/**
* don't overload in other builders, use @c openNamespace and @c closeNamespace instead.
*/
......
......@@ -826,7 +826,6 @@ void ExpressionVisitor::visitClassNameReference(ClassNameReferenceAst* node)
} while(it->hasNext() && (it = it->next));
}
}
}
void ExpressionVisitor::visitClassNameReferenceDimListItems(ClassPropertyAst* node)
......
......@@ -88,6 +88,29 @@ void TestUses::functionCall()
QCOMPARE(fun->uses().keys().first(), IndexedString(QUrl("file:///internal/usestest/functionCall.php")));
}
void TestUses::functionCallWithClosureArgs()
{
// 0 1 2 3 4 5 6 7 8 9
// 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
QByteArray method("<? function foo($a, $b) {} $c = []; $d = []; foo(function ($x) use ($c) { return $c[$x]; }, $d); ");
TopDUContext* top = parse(method, DumpNone);
DUChainReleaser releaseTop(top);
DUChainWriteLocker lock(DUChain::lock());
// foo
Declaration* fun = top->localDeclarations().first();
compareUses(fun, RangeInRevision(0, 45, 0, 48));
// $c
Declaration* c = top->localDeclarations().at(1);
compareUses(c, QList<RangeInRevision>() << RangeInRevision(0, 68, 0, 70) << RangeInRevision(0, 81, 0, 83));
// $d
Declaration* d = top->localDeclarations().at(2);
compareUses(d, RangeInRevision(0, 92, 0, 94));
}
void TestUses::memberFunctionCall()
{
......
......@@ -33,6 +33,7 @@ public:
private slots:
void newObject();
void functionCall();
void functionCallWithClosureArgs();
void memberFunctionCall();
void unsureMemberFunctionCall();
void memberVariable();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment