summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinz Wiesinger <pprkut@liwjatan.at>2017-06-19 10:53:14 (GMT)
committerHeinz Wiesinger <pprkut@liwjatan.at>2017-06-19 13:23:45 (GMT)
commit2bc3f4d2e613f7a5daed47c9119de149e253927b (patch)
treea7352ed25da5b62fc56aa5ca2404bbf1d1b300b3
parent1cb4b3e37e5caec095a6e14ebbc561616d9897ad (diff)
Support more cases of function argument unpacking.
Subscribers: apol, kdevelop-devel Differential Revision: https://phabricator.kde.org/D6271
-rw-r--r--duchain/tests/duchain.cpp22
-rw-r--r--duchain/tests/duchain.h1
-rw-r--r--parser/php.g2
3 files changed, 15 insertions, 10 deletions
diff --git a/duchain/tests/duchain.cpp b/duchain/tests/duchain.cpp
index 74eeb6b..5fe9021 100644
--- a/duchain/tests/duchain.cpp
+++ b/duchain/tests/duchain.cpp
@@ -3045,21 +3045,25 @@ void TestDUChain::staticFunctionClassPhp54()
QCOMPARE(classDec->uses().count(),1);
}
+void TestDUChain::functionArgumentUnpacking_data()
+{
+ QTest::addColumn<QString>("code");
+
+ QTest::newRow("unpackVariable") << QStringLiteral("<? $a = [ 1,2 ];\n$b = [ 3,4 ];\nfunction aaa($c,$d,$e,$f) { }\naaa(...$a, ...$b);\n");
+
+ QTest::newRow("unpackLiteral") << QStringLiteral("<? function aaa($c,$d,$e,$f) { }\naaa(...[1,2], ...[3,4]);\n");
+
+ QTest::newRow("unpackFunction") << QStringLiteral("<? function bbb() { return [1,2,3,4]; }\nfunction aaa($c,$d,$e,$f) { }\naaa(...bbb());\n");
+}
+
void TestDUChain::functionArgumentUnpacking()
{
- // 0 1 2 3 4 5 6 7
- // 01234567890123456789012345678901234567890123456789012345678901234567890123456789
- QByteArray method("<?php\n"
- "$a = [ 1,2 ];\n"
- "$b = [ 3,4 ];\n"
- "function aaa($c,$d,$e,$f) { }\n"
- "aaa(...$a, ...$b);\n");
+ QFETCH(QString, code);
- TopDUContext* top = parse(method);
+ TopDUContext* top = parse(code.toUtf8(), DumpNone);
QVERIFY(top);
DUChainReleaser releaseTop(top);
DUChainWriteLocker lock(DUChain::lock());
QVERIFY(top->problems().isEmpty());
- QCOMPARE(top->localDeclarations().count(),3);
}
diff --git a/duchain/tests/duchain.h b/duchain/tests/duchain.h
index 96f5d01..5c9db65 100644
--- a/duchain/tests/duchain.h
+++ b/duchain/tests/duchain.h
@@ -153,6 +153,7 @@ private slots:
void useThisAsArray();
void wrongUseOfThisAsArray();
void staticFunctionClassPhp54();
+ void functionArgumentUnpacking_data();
void functionArgumentUnpacking();
};
diff --git a/parser/php.g b/parser/php.g
index 4a15123..b758bcb 100644
--- a/parser/php.g
+++ b/parser/php.g
@@ -599,7 +599,7 @@ expression=booleanOrExpression
#parameters=functionCallParameterListElement @ COMMA | 0
-> functionCallParameterList ;;
- (BIT_AND variable=variable) | (isVariadic=ELLIPSIS variable=variable) | expr=expr
+ (BIT_AND variable=variable) | (isVariadic=ELLIPSIS | 0) expr=expr
-> functionCallParameterListElement ;;
#element=assignmentListElement @COMMA