@malloydata/malloy 0.0.163-dev240807165545 → 0.0.163-dev240808155642
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -321,14 +321,6 @@ function compare(fs, left, op, right) {
|
|
|
321
321
|
function oneOf(op, ...operators) {
|
|
322
322
|
return operators.includes(op);
|
|
323
323
|
}
|
|
324
|
-
function allAre(oneType, ...values) {
|
|
325
|
-
for (const v of values) {
|
|
326
|
-
if (v.dataType !== oneType) {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return true;
|
|
331
|
-
}
|
|
332
324
|
function numeric(fs, left, op, right) {
|
|
333
325
|
const lhs = left.getExpression(fs);
|
|
334
326
|
const rhs = right.getExpression(fs);
|
|
@@ -340,7 +332,13 @@ function numeric(fs, left, op, right) {
|
|
|
340
332
|
return noGo;
|
|
341
333
|
}
|
|
342
334
|
const expressionType = (0, malloy_types_1.maxExpressionType)(lhs.expressionType, rhs.expressionType);
|
|
343
|
-
if (
|
|
335
|
+
if (lhs.dataType !== 'number') {
|
|
336
|
+
left.log(`The '${op}' operator requires a number, not a '${lhs.dataType}'`);
|
|
337
|
+
}
|
|
338
|
+
else if (rhs.dataType !== 'number') {
|
|
339
|
+
right.log(`The '${op}' operator requires a number, not a '${rhs.dataType}'`);
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
344
342
|
return {
|
|
345
343
|
dataType: 'number',
|
|
346
344
|
expressionType,
|
|
@@ -348,9 +346,6 @@ function numeric(fs, left, op, right) {
|
|
|
348
346
|
evalSpace: (0, malloy_types_1.mergeEvalSpaces)(lhs.evalSpace, rhs.evalSpace),
|
|
349
347
|
};
|
|
350
348
|
}
|
|
351
|
-
// TODO make the error location be the operand that is not a number, rather than
|
|
352
|
-
// always the first operand
|
|
353
|
-
left.log(`Non numeric('${lhs.dataType},${rhs.dataType}') value with '${op}'`);
|
|
354
349
|
return (0, ast_utils_1.errorFor)('numbers required');
|
|
355
350
|
}
|
|
356
351
|
function delta(fs, left, op, right) {
|
|
@@ -82,6 +82,14 @@ describe('expressions', () => {
|
|
|
82
82
|
test('addition', () => {
|
|
83
83
|
expect((0, test_translator_1.expr) `42 + 7`).toTranslate();
|
|
84
84
|
});
|
|
85
|
+
test('typecheck addition lhs', () => {
|
|
86
|
+
const wrong = (0, test_translator_1.expr) `${'"string"'} + 1`;
|
|
87
|
+
expect(wrong).translationToFailWith("The '+' operator requires a number, not a 'string'");
|
|
88
|
+
});
|
|
89
|
+
test('typecheck addition rhs', () => {
|
|
90
|
+
const wrong = (0, test_translator_1.expr) `1 + ${'"string"'}`;
|
|
91
|
+
expect(wrong).translationToFailWith("The '+' operator requires a number, not a 'string'");
|
|
92
|
+
});
|
|
85
93
|
test('subtraction', () => {
|
|
86
94
|
expect((0, test_translator_1.expr) `42 - 7`).toTranslate();
|
|
87
95
|
});
|
|
@@ -75,8 +75,8 @@ describe('parameters', () => {
|
|
|
75
75
|
test('no additional error if default value type is error', () => {
|
|
76
76
|
expect((0, test_translator_1.markSource) `
|
|
77
77
|
##! experimental.parameters
|
|
78
|
-
source: ab_new(param::number is 1 + "foo") is ab
|
|
79
|
-
`).translationToFailWith("
|
|
78
|
+
source: ab_new(param::number is 1 + ${'"foo"'}) is ab
|
|
79
|
+
`).translationToFailWith("The '+' operator requires a number, not a 'string'");
|
|
80
80
|
});
|
|
81
81
|
test('can declare parameter with inferred type', () => {
|
|
82
82
|
expect(`
|
|
@@ -417,7 +417,7 @@ describe('query:', () => {
|
|
|
417
417
|
test('function return type incorrect', () => {
|
|
418
418
|
expect(`run: a -> {
|
|
419
419
|
group_by: s is floor(1.2) + 'a'
|
|
420
|
-
}`).translationToFailWith("
|
|
420
|
+
}`).translationToFailWith("The '+' operator requires a number, not a 'string'");
|
|
421
421
|
});
|
|
422
422
|
test('can use output value in calculate', () => {
|
|
423
423
|
expect(`run: a -> {
|