Skip to content

Commit eb5823f

Browse files
committed
Improve error messages
1 parent 2e7a4d4 commit eb5823f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core/src/runtime/runtime.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,16 @@ export class Runtime {
689689
} else if(expr.operator == operators.subtract){
690690
fail(`Cannot subtract an enum value from a number`, expr);
691691
} else fail(f.quote`Expected the expression "$rc" to evaluate to a value of type ${guessedType}, but it returns an enum value`, expr.nodes[1]);
692+
} else if(left.typeIs('STRING') && right.typeIs('STRING')){
693+
fail({
694+
summary: 'Invalid operand types',
695+
elaboration: 'the addition operator (+) is used to add numbers',
696+
help: [
697+
'use the string concatenation operator (&) to join strings',
698+
!isNaN(Number(left.value)) && !isNaN(Number(right.value)) &&
699+
'to add the values of these strings, convert them to numbers using the STR_TO_NUM function',
700+
].filter(Boolean),
701+
}, expr.operatorToken, expr);
692702
} else {
693703
left = coerceValue(left.value, left.type, guessedType, expr.nodes[0]);
694704
right = coerceValue(right.value, right.type, guessedType, expr.nodes[1]);

0 commit comments

Comments
 (0)