Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core,test] Update expression style parsing test fixture.
Browse files Browse the repository at this point in the history
Always clear errors before trying automatic coercion for a new compound expression overload.
  • Loading branch information
ChrisLoer committed Sep 19, 2018
1 parent 3daa517 commit a133e33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
32 changes: 14 additions & 18 deletions src/mbgl/style/expression/compound_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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);
Expand All @@ -773,34 +772,31 @@ 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;
}
}
}
}
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();
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/style_parser/expressions.info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit a133e33

Please sign in to comment.