Skip to content

Commit

Permalink
Merge pull request #28474 from ProvableHQ/height_type_check
Browse files Browse the repository at this point in the history
Typecheck block.height.
  • Loading branch information
d0cd authored Dec 16, 2024
2 parents 2f49d3b + 385d17f commit 76a6fbc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/passes/src/type_checking/check_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ impl<'a, N: Network> ExpressionVisitor<'a> for TypeChecker<'a, N> {
sym::height => {
// Check that the operation is invoked in a `finalize` block.
self.check_access_allowed("block.height", true, access.name.span());
return Some(Type::Integer(IntegerType::U32));
return Some(self.assert_and_return_type(
Type::Integer(IntegerType::U32),
expected,
input.span(),
));
}
_ => {
self.emit_err(TypeCheckerError::invalid_block_access(access.name.span()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace = "Compile"
expectation = "Fail"
outputs = ["""
Error [ETYC0372003]: Expected type `u64` but type `u32` was found
--> compiler-test:5:22
|
5 | let x: u64 = block.height;
| ^^^^^^^^^^^^
"""]
14 changes: 14 additions & 0 deletions tests/tests/compiler/constants/block_height_type_fail.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
namespace = "Compile"
expectation = "Fail"
*/

program test.aleo {
async function bar() {
let x: u64 = block.height;
}

async transition foo() -> Future {
return bar();
}
}

0 comments on commit 76a6fbc

Please sign in to comment.