Fixes invalid parsing of function call with keyword args only 17/169717/3
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Thu, 8 Feb 2018 13:16:38 +0000 (14:16 +0100)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Thu, 8 Feb 2018 14:51:28 +0000 (14:51 +0000)
Call like foo(a = 1, b = 2) would fail, due to invalid parsing of second argument (b).

Change-Id: I4ca2558cf6d0e42d8b79c5c0a03490948415812b

src/batch/Parser.cpp
tests/no-ui-scenarios/BatchExecTests.cpp

index 7f41ebd..263f3b4 100644 (file)
@@ -206,7 +206,7 @@ class Parser
 
                while (index < tokens.size()) {
                        if (canConsume(")")) break;
-                       if (!args.empty() && !consume(",")) return false;
+                       if ((!args.empty() || !keywordArgs.empty()) && !consume(",")) return false;
                        if (index + 1 < tokens.size() && tokens[index].type() == TokenType::IDENTIFIER &&
                                        tokens[index + 1].text() == "=") {
                                alreadyKeywords = true;
index 6776851..66cc6a0 100644 (file)
@@ -459,6 +459,10 @@ TEST_F(ScriptTest, keywordArguments)
        expected = { 5, 6, 5, 3};
        ASSERT_EQ(val, expected);
 
+       execute("func(a1=5, a2=6, a4=3, a3=5)", ec, true);
+       expected = { 5, 6, 5, 3};
+       ASSERT_EQ(val, expected);
+
        try {
                execute("func(1,a3=5,a4=6)", ec, true);
                FAIL() << "didn't throw";