From fed55418f21719149e510a6c49836ba58a5da2c2 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Mon, 13 Aug 2018 15:29:44 -0700 Subject: [core,test] Update expression style parsing test fixture. Always clear errors before trying automatic coercion for a new compound expression overload. --- src/mbgl/style/expression/compound_expression.cpp | 32 ++++++++++------------- test/fixtures/style_parser/expressions.info.json | 2 +- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp index e4411fa335..05925810e4 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -742,8 +742,6 @@ ParseResult parseCompoundExpression(const std::string name, const Convertible& v auto length = arrayLength(value); - bool attemptedParse = false; - for (std::size_t j = 0; j < definition.size(); j++) { const std::unique_ptr& signature = definition[j]; @@ -753,6 +751,7 @@ ParseResult parseCompoundExpression(const std::string name, const Convertible& v ) { // First parse all the args, potentially coercing to the // types expected by this overload. + ctx.clearErrors(); bool argParseFailed = false; std::vector> args; args.reserve(length - 1); @@ -773,10 +772,8 @@ ParseResult parseCompoundExpression(const std::string name, const Convertible& v if (argParseFailed) { // Couldn't coerce args of this overload to expected type, move // on to next one. - ctx.clearErrors(); continue; } else { - attemptedParse = true; ParseResult parseWithArgs = createCompoundExpression(definition, std::move(args), ctx); if (parseWithArgs) { return parseWithArgs; @@ -784,23 +781,22 @@ ParseResult parseCompoundExpression(const std::string name, const Convertible& v } } } - if (!attemptedParse) { - // The args couldn't be coerced to any of the expected types. - // Parse the arguments again without expected types just for the error message - std::vector> args; - args.reserve(length - 1); - - for (std::size_t i = 1; i < length; i++) { - auto parsed = ctx.parse(arrayMember(value, i), i); - if (!parsed) { - return ParseResult(); - } - args.push_back(std::move(*parsed)); + // The args couldn't be coerced to any of the expected types. + // Parse the arguments again without expected types just for the error message + ctx.clearErrors(); + std::vector> args; + args.reserve(length - 1); + + for (std::size_t i = 1; i < length; i++) { + auto parsed = ctx.parse(arrayMember(value, i), i); + if (!parsed) { + return ParseResult(); } - - ctx.error(expectedTypesError(definition, args)); + args.push_back(std::move(*parsed)); } + ctx.error(expectedTypesError(definition, args)); + return ParseResult(); } diff --git a/test/fixtures/style_parser/expressions.info.json b/test/fixtures/style_parser/expressions.info.json index 4649227934..75fb70c1d2 100644 --- a/test/fixtures/style_parser/expressions.info.json +++ b/test/fixtures/style_parser/expressions.info.json @@ -2,7 +2,7 @@ "default": { "log": [ [1, "WARNING", "ParseStyle", "Expected color but found number instead."], - [1, "WARNING", "ParseStyle", "[2]: Expected number but found string instead."], + [1, "WARNING", "ParseStyle", "Expected arguments of type (number, number, number, number), but found (number, string, number, number) instead."], [1, "WARNING", "ParseStyle", "\"zoom\" expression may only be used as input to a top-level \"step\" or \"interpolate\" expression."], [1, "WARNING", "ParseStyle", "value must be a string"], [1, "WARNING", "ParseStyle", "data expressions not supported"], -- cgit v1.2.1