@@ -29,7 +29,9 @@ bool isSearchableRuntimeType(const type::Type& type) {
|
||||
} // namespace
|
||||
|
||||
In::In(std::unique_ptr<Expression> needle_, std::unique_ptr<Expression> haystack_)
|
||||
: Expression(Kind::In, type::Boolean), needle(std::move(needle_)), haystack(std::move(haystack_)) {
|
||||
: Expression(Kind::In, type::Boolean),
|
||||
needle(std::move(needle_)),
|
||||
haystack(std::move(haystack_)) {
|
||||
assert(isComparableType(needle->getType()));
|
||||
assert(isSearchableType(haystack->getType()));
|
||||
}
|
||||
@@ -47,14 +49,18 @@ EvaluationResult In::evaluate(const EvaluationContext& params) const {
|
||||
|
||||
type::Type evaluatedNeedleType = typeOf(*evaluatedNeedle);
|
||||
if (!isComparableRuntimeType(evaluatedNeedleType)) {
|
||||
return EvaluationError{"Expected first argument to be of type boolean, string or number, but found " +
|
||||
toString(evaluatedNeedleType) + " instead."};
|
||||
return EvaluationError{
|
||||
"Expected first argument to be of type boolean, string or number, "
|
||||
"but found " +
|
||||
toString(evaluatedNeedleType) + " instead."};
|
||||
}
|
||||
|
||||
type::Type evaluatedHaystackType = typeOf(*evaluatedHaystack);
|
||||
if (!isSearchableRuntimeType(evaluatedHaystackType)) {
|
||||
return EvaluationError{"Expected second argument to be of type array or string, but found " +
|
||||
toString(evaluatedHaystackType) + " instead."};
|
||||
return EvaluationError{
|
||||
"Expected second argument to be of type array or string, but "
|
||||
"found " +
|
||||
toString(evaluatedHaystackType) + " instead."};
|
||||
}
|
||||
|
||||
if (evaluatedNeedleType == type::Null || evaluatedHaystackType == type::Null) {
|
||||
@@ -97,14 +103,18 @@ ParseResult In::parse(const Convertible& value, ParsingContext& ctx) {
|
||||
type::Type haystackType = (*haystack)->getType();
|
||||
|
||||
if (!isComparableType(needleType)) {
|
||||
ctx.error("Expected first argument to be of type boolean, string or number, but found " + toString(needleType) +
|
||||
" instead.");
|
||||
ctx.error(
|
||||
"Expected first argument to be of type boolean, string or number, "
|
||||
"but found " +
|
||||
toString(needleType) + " instead.");
|
||||
return ParseResult();
|
||||
}
|
||||
|
||||
if (!isSearchableType(haystackType)) {
|
||||
ctx.error("Expected second argument to be of type array or string, but found " + toString(haystackType) +
|
||||
" instead.");
|
||||
ctx.error(
|
||||
"Expected second argument to be of type array or string, but "
|
||||
"found " +
|
||||
toString(haystackType) + " instead.");
|
||||
return ParseResult();
|
||||
}
|
||||
return ParseResult(std::make_unique<In>(std::move(*needle), std::move(*haystack)));
|
||||
|
||||
Reference in New Issue
Block a user