mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-17 08:51:34 +00:00
null checking throughout logical and/or
This commit is contained in:
@ -16,6 +16,10 @@
|
||||
(export "testWhile" (func $possibly-null/testWhile))
|
||||
(export "testWhile2" (func $possibly-null/testWhile2))
|
||||
(export "testWhile3" (func $possibly-null/testWhile3))
|
||||
(export "testLogicalAnd" (func $possibly-null/testTrue))
|
||||
(export "testLogicalOr" (func $possibly-null/testTrue))
|
||||
(export "testLogicalAndMulti" (func $possibly-null/testLogicalAndMulti))
|
||||
(export "testLogicalOrMulti" (func $possibly-null/testLogicalAndMulti))
|
||||
(func $possibly-null/testTrue (; 0 ;) (type $FUNCSIG$vi) (param $0 i32)
|
||||
nop
|
||||
)
|
||||
@ -52,7 +56,10 @@
|
||||
end
|
||||
end
|
||||
)
|
||||
(func $null (; 4 ;) (type $FUNCSIG$v)
|
||||
(func $possibly-null/testLogicalAndMulti (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
|
||||
nop
|
||||
)
|
||||
(func $null (; 5 ;) (type $FUNCSIG$v)
|
||||
nop
|
||||
)
|
||||
)
|
||||
|
@ -83,16 +83,30 @@ export function testWhile3(a: Ref | null, b: Ref | null): void {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
function requireNonNull(a: Ref): Ref {
|
||||
return a;
|
||||
}
|
||||
|
||||
// function requireNonNull(a: Ref): Ref {
|
||||
// return a;
|
||||
// }
|
||||
export function testLogicalAnd(a: Ref | null): void {
|
||||
a && requireNonNull(a);
|
||||
}
|
||||
|
||||
// export function testLogicalAnd(a: Ref | null): void {
|
||||
// a && requireNonNull(a);
|
||||
// }
|
||||
export function testLogicalOr(a: Ref | null): void {
|
||||
!a || requireNonNull(a) != null;
|
||||
}
|
||||
|
||||
// export function testLogicalOr(a: Ref | null): void {
|
||||
// !a || requireNonNull(a);
|
||||
// }
|
||||
export function testLogicalAndMulti(a: Ref | null, b: Ref | null): void {
|
||||
if (a && b) {
|
||||
if (isNullable(a)) ERROR("should be non-nullable");
|
||||
if (isNullable(b)) ERROR("should be non-nullable");
|
||||
}
|
||||
}
|
||||
|
||||
export function testLogicalOrMulti(a: Ref | null, b: Ref | null): void {
|
||||
if (!a || !b) {
|
||||
// something
|
||||
} else {
|
||||
if (isNullable(a)) ERROR("should be non-nullable");
|
||||
if (isNullable(b)) ERROR("should be non-nullable");
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
(module
|
||||
(type $FUNCSIG$vi (func (param i32)))
|
||||
(type $FUNCSIG$vii (func (param i32 i32)))
|
||||
(type $FUNCSIG$ii (func (param i32) (result i32)))
|
||||
(type $FUNCSIG$v (func))
|
||||
(memory $0 0)
|
||||
(table $0 1 funcref)
|
||||
@ -18,6 +19,10 @@
|
||||
(export "testWhile" (func $possibly-null/testWhile))
|
||||
(export "testWhile2" (func $possibly-null/testWhile2))
|
||||
(export "testWhile3" (func $possibly-null/testWhile3))
|
||||
(export "testLogicalAnd" (func $possibly-null/testLogicalAnd))
|
||||
(export "testLogicalOr" (func $possibly-null/testLogicalOr))
|
||||
(export "testLogicalAndMulti" (func $possibly-null/testLogicalAndMulti))
|
||||
(export "testLogicalOrMulti" (func $possibly-null/testLogicalOrMulti))
|
||||
(func $possibly-null/testTrue (; 0 ;) (type $FUNCSIG$vi) (param $0 i32)
|
||||
local.get $0
|
||||
if
|
||||
@ -128,6 +133,58 @@
|
||||
end
|
||||
end
|
||||
)
|
||||
(func $null (; 12 ;) (type $FUNCSIG$v)
|
||||
(func $possibly-null/requireNonNull (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
|
||||
local.get $0
|
||||
)
|
||||
(func $possibly-null/testLogicalAnd (; 13 ;) (type $FUNCSIG$vi) (param $0 i32)
|
||||
local.get $0
|
||||
if (result i32)
|
||||
local.get $0
|
||||
call $possibly-null/requireNonNull
|
||||
else
|
||||
i32.const 0
|
||||
end
|
||||
drop
|
||||
)
|
||||
(func $possibly-null/testLogicalOr (; 14 ;) (type $FUNCSIG$vi) (param $0 i32)
|
||||
local.get $0
|
||||
i32.eqz
|
||||
if (result i32)
|
||||
i32.const 1
|
||||
else
|
||||
local.get $0
|
||||
call $possibly-null/requireNonNull
|
||||
i32.const 0
|
||||
i32.ne
|
||||
end
|
||||
drop
|
||||
)
|
||||
(func $possibly-null/testLogicalAndMulti (; 15 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
|
||||
local.get $0
|
||||
if (result i32)
|
||||
local.get $1
|
||||
else
|
||||
i32.const 0
|
||||
end
|
||||
if
|
||||
nop
|
||||
end
|
||||
)
|
||||
(func $possibly-null/testLogicalOrMulti (; 16 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
|
||||
local.get $0
|
||||
i32.eqz
|
||||
if (result i32)
|
||||
i32.const 1
|
||||
else
|
||||
local.get $1
|
||||
i32.eqz
|
||||
end
|
||||
if
|
||||
nop
|
||||
else
|
||||
nop
|
||||
end
|
||||
)
|
||||
(func $null (; 17 ;) (type $FUNCSIG$v)
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user