add typechecks for bitshifts ops

This commit is contained in:
aoyako 2024-02-25 21:36:55 +09:00
parent cc3db584f2
commit fe887e2565

View File

@ -173,7 +173,7 @@ func TypeFromBinaryOp(op Op, lhst, rhst Type, lhsConst, rhsConst constant.Value)
return Type{}, false return Type{}, false
} }
if op == And || op == Or || op == Xor { if op == And || op == Or || op == Xor || op == LeftShift || op == RightShift {
if lhst.Main == Int && rhst.Main == Int { if lhst.Main == Int && rhst.Main == Int {
return Type{Main: Int}, true return Type{Main: Int}, true
} }
@ -190,7 +190,9 @@ func TypeFromBinaryOp(op Op, lhst, rhst Type, lhsConst, rhsConst constant.Value)
return lhst, true return lhst, true
} }
if lhst.Main == Int && rhst.IsIntVector() { if lhst.Main == Int && rhst.IsIntVector() {
return rhst, true if op == And || op == Or || op == Xor {
return rhst, true
}
} }
return Type{}, false return Type{}, false
} }