mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 18:52:58 +03:00
check signed ints for abs and abs.w
This commit is contained in:
parent
811eaadc98
commit
d4171de577
@ -483,12 +483,12 @@ impl<'a> ExpressionVisitorDirector<'a> for Director<'a> {
|
|||||||
match input.op {
|
match input.op {
|
||||||
UnaryOperation::Abs => {
|
UnaryOperation::Abs => {
|
||||||
// Assert integer type only.
|
// Assert integer type only.
|
||||||
self.visitor.assert_int_type(destination, input.span());
|
self.visitor.assert_singed_int_type(destination, input.span());
|
||||||
self.visit_expression(&input.receiver, destination)
|
self.visit_expression(&input.receiver, destination)
|
||||||
}
|
}
|
||||||
UnaryOperation::AbsWrapped => {
|
UnaryOperation::AbsWrapped => {
|
||||||
// Assert integer type only.
|
// Assert integer type only.
|
||||||
self.visitor.assert_int_type(destination, input.span());
|
self.visitor.assert_singed_int_type(destination, input.span());
|
||||||
self.visit_expression(&input.receiver, destination)
|
self.visit_expression(&input.receiver, destination)
|
||||||
}
|
}
|
||||||
UnaryOperation::Double => {
|
UnaryOperation::Double => {
|
||||||
|
@ -45,6 +45,14 @@ const INT_TYPES: [Type; 10] = [
|
|||||||
Type::IntegerType(IntegerType::U128),
|
Type::IntegerType(IntegerType::U128),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const SIGNED_INT_TYPES: [Type; 5] = [
|
||||||
|
Type::IntegerType(IntegerType::I8),
|
||||||
|
Type::IntegerType(IntegerType::I16),
|
||||||
|
Type::IntegerType(IntegerType::I32),
|
||||||
|
Type::IntegerType(IntegerType::I64),
|
||||||
|
Type::IntegerType(IntegerType::I128),
|
||||||
|
];
|
||||||
|
|
||||||
const MAGNITUDE_TYPES: [Type; 3] = [
|
const MAGNITUDE_TYPES: [Type; 3] = [
|
||||||
Type::IntegerType(IntegerType::U8),
|
Type::IntegerType(IntegerType::U8),
|
||||||
Type::IntegerType(IntegerType::U16),
|
Type::IntegerType(IntegerType::U16),
|
||||||
@ -227,6 +235,11 @@ impl<'a> TypeChecker<'a> {
|
|||||||
self.assert_one_of_types(type_, &INT_TYPES, span)
|
self.assert_one_of_types(type_, &INT_TYPES, span)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Emits an error to the handler if the given type is not a signed integer.
|
||||||
|
pub(crate) fn assert_singed_int_type(&self, type_: &Option<Type>, span: Span) {
|
||||||
|
self.assert_one_of_types(type_, &SIGNED_INT_TYPES, span)
|
||||||
|
}
|
||||||
|
|
||||||
/// Emits an error to the handler if the given type is not a magnitude (u8, u16, u32).
|
/// Emits an error to the handler if the given type is not a magnitude (u8, u16, u32).
|
||||||
pub(crate) fn assert_magnitude_type(&self, type_: &Option<Type>, span: Span) {
|
pub(crate) fn assert_magnitude_type(&self, type_: &Option<Type>, span: Span) {
|
||||||
self.assert_one_of_types(type_, &MAGNITUDE_TYPES, span)
|
self.assert_one_of_types(type_, &MAGNITUDE_TYPES, span)
|
||||||
|
@ -146,7 +146,6 @@ symbols! {
|
|||||||
hash,
|
hash,
|
||||||
ped64: "Pedersen64",
|
ped64: "Pedersen64",
|
||||||
ped128: "Pedersen128",
|
ped128: "Pedersen128",
|
||||||
prf,
|
|
||||||
psd2: "Poseidon2",
|
psd2: "Poseidon2",
|
||||||
psd4: "Poseidon4",
|
psd4: "Poseidon4",
|
||||||
psd8: "Poseidon8",
|
psd8: "Poseidon8",
|
||||||
|
Loading…
Reference in New Issue
Block a user