From eeeaeffae6e92080de38b4f18b51beb7e9ad1f15 Mon Sep 17 00:00:00 2001 From: Radoslaw Cybulski Date: Thu, 8 Feb 2018 14:16:38 +0100 Subject: [PATCH] Fixes invalid parsing of function call with keyword args only Call like foo(a = 1, b = 2) would fail, due to invalid parsing of second argument (b). Change-Id: I4ca2558cf6d0e42d8b79c5c0a03490948415812b --- src/batch/Parser.cpp | 2 +- tests/no-ui-scenarios/BatchExecTests.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/batch/Parser.cpp b/src/batch/Parser.cpp index 7f41ebd..263f3b4 100644 --- a/src/batch/Parser.cpp +++ b/src/batch/Parser.cpp @@ -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; diff --git a/tests/no-ui-scenarios/BatchExecTests.cpp b/tests/no-ui-scenarios/BatchExecTests.cpp index 6776851..66cc6a0 100644 --- a/tests/no-ui-scenarios/BatchExecTests.cpp +++ b/tests/no-ui-scenarios/BatchExecTests.cpp @@ -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"; -- 2.7.4