mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-20 18:26:40 +00:00
Report if a function isn't guaranteed to return
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
(export "ifThenElse" (func $if/ifThenElse))
|
||||
(export "ifThen" (func $if/ifThen))
|
||||
(export "ifThenElseBlock" (func $if/ifThenElse))
|
||||
(export "ifAlwaysReturns" (func $if/ifAlwaysReturns))
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $if/ifThenElse (; 0 ;) (type $ii) (param $0 i32) (result i32)
|
||||
@ -23,7 +24,16 @@
|
||||
)
|
||||
(i32.const 0)
|
||||
)
|
||||
(func $start (; 2 ;) (type $v)
|
||||
(func $if/ifAlwaysReturns (; 2 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(if
|
||||
(get_local $0)
|
||||
(return
|
||||
(i32.const 1)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(func $start (; 3 ;) (type $v)
|
||||
(if
|
||||
(call $if/ifThenElse
|
||||
(i32.const 0)
|
||||
|
@ -29,3 +29,10 @@ export function ifThenElseBlock(n: i32): bool {
|
||||
|
||||
assert(ifThenElseBlock(0) == false);
|
||||
assert(ifThenElseBlock(1) == true);
|
||||
|
||||
export function ifAlwaysReturns(n: i32): bool {
|
||||
if (n)
|
||||
return true;
|
||||
else
|
||||
throw new Error("error");
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
(export "ifThenElse" (func $if/ifThenElse))
|
||||
(export "ifThen" (func $if/ifThen))
|
||||
(export "ifThenElseBlock" (func $if/ifThenElseBlock))
|
||||
(export "ifAlwaysReturns" (func $if/ifAlwaysReturns))
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $if/ifThenElse (; 0 ;) (type $ii) (param $0 i32) (result i32)
|
||||
@ -47,7 +48,16 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $start (; 3 ;) (type $v)
|
||||
(func $if/ifAlwaysReturns (; 3 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(if
|
||||
(get_local $0)
|
||||
(return
|
||||
(i32.const 1)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(func $start (; 4 ;) (type $v)
|
||||
(if
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
@ -163,8 +173,10 @@
|
||||
FUNCTION_PROTOTYPE: if/ifThenElse
|
||||
FUNCTION_PROTOTYPE: if/ifThen
|
||||
FUNCTION_PROTOTYPE: if/ifThenElseBlock
|
||||
FUNCTION_PROTOTYPE: if/ifAlwaysReturns
|
||||
[program.exports]
|
||||
FUNCTION_PROTOTYPE: if/ifThenElse
|
||||
FUNCTION_PROTOTYPE: if/ifThen
|
||||
FUNCTION_PROTOTYPE: if/ifThenElseBlock
|
||||
FUNCTION_PROTOTYPE: if/ifAlwaysReturns
|
||||
;)
|
||||
|
Reference in New Issue
Block a user