Skip to content

Commit 49bb5aa

Browse files
committed
fix: arithmetic type inference
1 parent 1d6e3ab commit 49bb5aa

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

language/src/language/control/utils/type-inference-utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,9 @@ export class TypeInferenceUtils {
577577
accept: ValidationAcceptor,
578578
expr: any
579579
): string | undefined {
580-
const numericTypes = ["INT", "REAL"];
580+
const numericTypes = new Set(["INT", "REAL"]);
581581

582-
if (!numericTypes.includes(left) || !numericTypes.includes(right)) {
582+
if (!numericTypes.has(left) || !numericTypes.has(right)) {
583583
accept(
584584
"error",
585585
`Arithmetic operator '${op}' requires numeric operands, but got '${left}' and '${right}'.`,
@@ -588,11 +588,11 @@ export class TypeInferenceUtils {
588588
return undefined;
589589
}
590590

591-
// If either operand is REAL, result is REAL
592-
if (left === "REAL" || right === "REAL") {
593-
return "REAL";
591+
// If either operand is INT, result is INT
592+
if (left === "INT" || right === "INT") {
593+
return "INT";
594594
}
595595

596-
return "INT";
596+
return "REAL";
597597
}
598598
}

language/test/validating/validating.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ describe("BCS Control Validation Tests", () => {
202202

203203
expect(allDiagnostics.length).toBe(1);
204204
const expectedMessages = [
205-
"Condition in 'when (...)' of unit 'Test' must be of type BOOL, but got 'REAL'.",
205+
"Condition in 'when (...)' of unit 'Test' must be of type BOOL, but got 'INT'.",
206206
];
207207

208208
expectedMessages.forEach((msg) => {

0 commit comments

Comments
 (0)