[core,test] Update expression style parsing test fixture.
Always clear errors before trying automatic coercion for a new compound expression overload.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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"],
|
||||
|
||||
Reference in New Issue
Block a user