mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-11 16:10:09 +03:00
Merge pull request #330 from AleoHQ/feature/unsigned-array-access-only
Add compiler check for signed integer array access
This commit is contained in:
commit
afc8c6b931
@ -83,8 +83,9 @@ impl IntegerError {
|
||||
}
|
||||
|
||||
pub fn invalid_index(span: Span) -> Self {
|
||||
let message =
|
||||
format!("index must be a constant value integer. allocated indices produce a circuit of unknown size");
|
||||
let message = format!(
|
||||
"index must be a constant value unsigned integer. allocated indices produce a circuit of unknown size"
|
||||
);
|
||||
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
@ -154,7 +154,10 @@ impl Integer {
|
||||
}
|
||||
|
||||
pub fn to_usize(&self, span: Span) -> Result<usize, IntegerError> {
|
||||
let value = self.get_value().ok_or(IntegerError::invalid_index(span.clone()))?;
|
||||
let unsigned_integer = self;
|
||||
let value_option: Option<String> = match_unsigned_integer!(unsigned_integer => unsigned_integer.get_value());
|
||||
|
||||
let value = value_option.ok_or(IntegerError::invalid_index(span.clone()))?;
|
||||
let value_usize = value
|
||||
.parse::<usize>()
|
||||
.map_err(|_| IntegerError::invalid_integer(value, span))?;
|
||||
|
@ -65,6 +65,21 @@ macro_rules! match_integer {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! match_unsigned_integer {
|
||||
($integer: ident => $expression: expr) => {
|
||||
match $integer {
|
||||
Integer::U8($integer) => $expression,
|
||||
Integer::U16($integer) => $expression,
|
||||
Integer::U32($integer) => $expression,
|
||||
Integer::U64($integer) => $expression,
|
||||
Integer::U128($integer) => $expression,
|
||||
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! match_signed_integer {
|
||||
($integer: ident, $span: ident => $expression: expr) => {
|
||||
|
Loading…
Reference in New Issue
Block a user