Skip to content

Commit

Permalink
[Typer] Check bitwise ops
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed Sep 18, 2024
1 parent 81bf3aa commit 1ff8ca6
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions source/compiler/typer.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -3524,6 +3524,56 @@ class Typer {
}

types.set(node, typeRight)

// TODO More of them
let mathTokens [Token] = [
Token.BitwiseXor,
Token.BitwiseOr,
Token.BitwiseAnd
]

if mathTokens.includes(op) {
// TODO could be optimized to ArrayByValue here
// or just allocate a normal class on stack
// cause values are possibly primitives?
let integers = [
typeInt,
// TODO big int etc

typeUInt64,
typeUInt32,
typeUInt16,
typeUInt8,

typeInt64,
typeInt32,
typeInt16,
typeInt8
]

if not integers.includes(typeLeft) or not integers.includes(typeRight) {
let tokenString = Token.stringify(op)

let leftString = switch a {
case Null:
'null'
case _:
Type.stringify(typeA)
}

let rightString = switch b {
case Null:
'null'
case _:
Type.stringify(typeB)
}

fail(
'Operator `a \(tokenString) b` requires `a` and `b` of integer types, but got `\(leftString)` and `\(rightString)`',
b
)
}
}
}

// `op e` or `e op`
Expand Down

0 comments on commit 1ff8ca6

Please sign in to comment.