mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-21 12:07:56 +03:00
Merge pull request #2146 from AleoHQ/fix/tyc-for-loop-bounds
Fix/tyc for loop bounds
This commit is contained in:
commit
c4279e2a83
@ -322,6 +322,8 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
// If `input.start` is a literal, instantiate it as a value.
|
||||
if let Expression::Literal(literal) = &input.start {
|
||||
input.start_value.replace(Some(Value::from(literal)));
|
||||
} else {
|
||||
self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.start.span()));
|
||||
}
|
||||
|
||||
self.visit_expression(&input.stop, iter_type);
|
||||
@ -329,6 +331,8 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> {
|
||||
// If `input.stop` is a literal, instantiate it as a value.
|
||||
if let Expression::Literal(literal) = &input.stop {
|
||||
input.stop_value.replace(Some(Value::from(literal)));
|
||||
} else {
|
||||
self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.stop.span()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -423,4 +423,11 @@ create_messages!(
|
||||
msg: format!("Cannot call a local transition function from a transition function."),
|
||||
help: None,
|
||||
}
|
||||
|
||||
@formatted
|
||||
loop_bound_must_be_a_literal {
|
||||
args: (),
|
||||
msg: format!("Loop bound must be a literal."),
|
||||
help: None,
|
||||
}
|
||||
);
|
||||
|
24
tests/compiler/statements/loop_non_literal_bound_fail.leo
Normal file
24
tests/compiler/statements/loop_non_literal_bound_fail.leo
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
program test.aleo {
|
||||
record Token {
|
||||
owner: address,
|
||||
gates: u64,
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
transition main(owner: address, amount: u64) -> Token {
|
||||
let max: u64 = 0u64;
|
||||
for i:u64 in 0u64..amount {
|
||||
max = i;
|
||||
}
|
||||
return Token {
|
||||
owner: owner,
|
||||
gates: 0u64,
|
||||
amount: amount,
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:12:28\n |\n 12 | for i:u64 in 0u64..amount {\n | ^^^^^^\n"
|
Loading…
Reference in New Issue
Block a user