Skip to content

Commit 1ff8ca6

Browse files
committed
[Typer] Check bitwise ops
1 parent 81bf3aa commit 1ff8ca6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

source/compiler/typer.hexa

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,6 +3524,56 @@ class Typer {
35243524
}
35253525

35263526
types.set(node, typeRight)
3527+
3528+
// TODO More of them
3529+
let mathTokens [Token] = [
3530+
Token.BitwiseXor,
3531+
Token.BitwiseOr,
3532+
Token.BitwiseAnd
3533+
]
3534+
3535+
if mathTokens.includes(op) {
3536+
// TODO could be optimized to ArrayByValue here
3537+
// or just allocate a normal class on stack
3538+
// cause values are possibly primitives?
3539+
let integers = [
3540+
typeInt,
3541+
// TODO big int etc
3542+
3543+
typeUInt64,
3544+
typeUInt32,
3545+
typeUInt16,
3546+
typeUInt8,
3547+
3548+
typeInt64,
3549+
typeInt32,
3550+
typeInt16,
3551+
typeInt8
3552+
]
3553+
3554+
if not integers.includes(typeLeft) or not integers.includes(typeRight) {
3555+
let tokenString = Token.stringify(op)
3556+
3557+
let leftString = switch a {
3558+
case Null:
3559+
'null'
3560+
case _:
3561+
Type.stringify(typeA)
3562+
}
3563+
3564+
let rightString = switch b {
3565+
case Null:
3566+
'null'
3567+
case _:
3568+
Type.stringify(typeB)
3569+
}
3570+
3571+
fail(
3572+
'Operator `a \(tokenString) b` requires `a` and `b` of integer types, but got `\(leftString)` and `\(rightString)`',
3573+
b
3574+
)
3575+
}
3576+
}
35273577
}
35283578

35293579
// `op e` or `e op`

0 commit comments

Comments
 (0)