diff --git a/compiler/passes/src/type_checking/check_expressions.rs b/compiler/passes/src/type_checking/check_expressions.rs index 488ba84241..950621ecd4 100644 --- a/compiler/passes/src/type_checking/check_expressions.rs +++ b/compiler/passes/src/type_checking/check_expressions.rs @@ -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())); diff --git a/tests/expectations/compiler/constants/block_height_type_fail.out b/tests/expectations/compiler/constants/block_height_type_fail.out new file mode 100644 index 0000000000..fcb4df4d49 --- /dev/null +++ b/tests/expectations/compiler/constants/block_height_type_fail.out @@ -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; + | ^^^^^^^^^^^^ +"""] diff --git a/tests/tests/compiler/constants/block_height_type_fail.leo b/tests/tests/compiler/constants/block_height_type_fail.leo new file mode 100644 index 0000000000..a933a3b433 --- /dev/null +++ b/tests/tests/compiler/constants/block_height_type_fail.leo @@ -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(); + } +}