mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-22 22:44:47 +03:00
Forbit explicit inclusion of async function return type
This commit is contained in:
parent
5790124de4
commit
b422657944
@ -629,7 +629,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
|
||||
// Async functions return a single future.
|
||||
let mut ret = if func.variant == AsyncFunction {
|
||||
if let Some(Type::Future(_)) = expected {
|
||||
Type::Future(FutureType::new(Vec::new()))
|
||||
Type::Future(FutureType::new(Vec::new(), Some(Location::new(input.program, ident.name))))
|
||||
} else {
|
||||
self.emit_err(TypeCheckerError::return_type_of_finalize_function_is_future(input.span));
|
||||
Type::Unit
|
||||
|
@ -928,7 +928,7 @@ create_messages!(
|
||||
finalize_function_cannot_return_value {
|
||||
args: (),
|
||||
msg: "An async function is not allowed to return a value.".to_string(),
|
||||
help: Some("Remove an output type in the function signature, and remove the return statement from the function.".to_string()),
|
||||
help: Some("Remove an output type in the function signature, and remove the return statement from the function. Note that the future returned by async functions is automatically inferred, and must not be explicitly written.".to_string()),
|
||||
}
|
||||
|
||||
@formatted
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [ETYC0372118]: An async function is not allowed to return a value.\n --> compiler-test:10:5\n |\n 10 | async function finalize() -> Future {\n 11 | Mapping::set(foo, 1u32, 1u32);\n 12 | }\n | ^\n |\n = Remove an output type in the function signature, and remove the return statement from the function. Note that the future returned by async functions is automatically inferred, and must not be explicitly written.\nError [ETYC0372038]: Function must return a value.\n --> compiler-test:10:5\n |\n 10 | async function finalize() -> Future {\n 11 | Mapping::set(foo, 1u32, 1u32);\n 12 | }\n | ^\n"
|
33
tests/tests/compiler/futures/explicit_return_type_fail.leo
Normal file
33
tests/tests/compiler/futures/explicit_return_type_fail.leo
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
program test.aleo {
|
||||
mapping foo: u32 => u32;
|
||||
async transition main_inner(public a: u32, b: u32) -> (u32, Future) {
|
||||
let c: u32 = a + b;
|
||||
let f: Future = finalize();
|
||||
return (c, f);
|
||||
}
|
||||
|
||||
async function finalize() -> Future {
|
||||
Mapping::set(foo, 1u32, 1u32);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Next Program --- //
|
||||
|
||||
import test.aleo;
|
||||
program basic.aleo {
|
||||
async transition main(public a: u32, b: u32) -> (u32, Future) {
|
||||
let c: u32 = a + b;
|
||||
let (d, f1): (u32, Future) = test.aleo/main_inner(1u32, 1u32);
|
||||
let f:Future = finalize(c, f1);
|
||||
return (c,f);
|
||||
}
|
||||
|
||||
async function finalize(input: u32, f: Future) {
|
||||
f.await();
|
||||
assert_eq(input, 1u32);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user