Skip to content
Snippets Groups Projects
Unverified Commit a287a4fb authored by Ariya Hidayat's avatar Ariya Hidayat Committed by GitHub
Browse files

Fix type-checking with COALESCE (#19157)

parent 78ca3471
No related branches found
No related tags found
No related merge requests found
......@@ -78,7 +78,11 @@ export function typeCheck(cst, rootType) {
if (type === "number") {
const op = getMBQLName(name);
const returnType = MBQL_CLAUSES[op].type;
if (returnType !== "number" && returnType !== "string") {
if (
returnType !== "number" &&
returnType !== "string" &&
returnType !== "expression"
) {
const message = t`Expecting ${type} but found function ${name} returning ${returnType}`;
this.errors.push({ message });
}
......
......@@ -190,6 +190,10 @@ describe("type-checker", () => {
expect(() => validate("Lower([State]) > 'AB'")).not.toThrow();
});
it("should allow a comparison on the result of COALESCE", () => {
expect(() => validate("Coalesce([X],[Y]) > 0")).not.toThrow();
});
it("should reject a less/greater comparison on functions returning boolean", () => {
expect(() => validate("IsEmpty([Tax]) < 5")).toThrow();
expect(() => validate("IsEmpty([Tax]) >= 0")).toThrow();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment