diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-08-13 15:29:44 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-10-15 13:15:46 -0700 |
commit | fed55418f21719149e510a6c49836ba58a5da2c2 (patch) | |
tree | 0d809e274f88bdbfea96b20c2a2d20ff2f56fb81 /src/mbgl | |
parent | 4a0aab8eb8754b2773cc29baa2c1b7d3ff01b336 (diff) | |
download | qtlocation-mapboxgl-fed55418f21719149e510a6c49836ba58a5da2c2.tar.gz |
[core,test] Update expression style parsing test fixture.
Always clear errors before trying automatic coercion for a new compound expression overload.
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/style/expression/compound_expression.cpp | 32 |
1 files changed, 14 insertions, 18 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<detail::SignatureBase>& 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<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> 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<std::unique_ptr<Expression>> 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(); } |