possible-null assignment to non-null, notes

This commit is contained in:
dcode
2019-04-09 06:57:28 +02:00
parent cd79376101
commit eb6c4c09ee
5 changed files with 84 additions and 53 deletions

View File

@ -20,6 +20,7 @@
(export "testLogicalOr" (func $possibly-null/testTrue))
(export "testLogicalAndMulti" (func $possibly-null/testLogicalAndMulti))
(export "testLogicalOrMulti" (func $possibly-null/testLogicalAndMulti))
(export "testAssign" (func $possibly-null/testLogicalAndMulti))
(func $possibly-null/testTrue (; 0 ;) (type $FUNCSIG$vi) (param $0 i32)
nop
)

View File

@ -99,14 +99,23 @@ 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");
} else {
if (!isNullable(a)) ERROR("should be nullable");
if (!isNullable(b)) ERROR("should be nullable");
}
}
export function testLogicalOrMulti(a: Ref | null, b: Ref | null): void {
if (!a || !b) {
// something
if (!isNullable(a)) ERROR("should be nullable");
if (!isNullable(b)) ERROR("should be nullable");
} else {
if (isNullable(a)) ERROR("should be non-nullable");
if (isNullable(b)) ERROR("should be non-nullable");
}
}
export function testAssign(a: Ref | null, b: Ref): void {
a = b;
if (isNullable(a)) ERROR("should be non-nullable");
}

View File

@ -23,6 +23,7 @@
(export "testLogicalOr" (func $possibly-null/testLogicalOr))
(export "testLogicalAndMulti" (func $possibly-null/testLogicalAndMulti))
(export "testLogicalOrMulti" (func $possibly-null/testLogicalOrMulti))
(export "testAssign" (func $possibly-null/testAssign))
(func $possibly-null/testTrue (; 0 ;) (type $FUNCSIG$vi) (param $0 i32)
local.get $0
if
@ -168,6 +169,8 @@
end
if
nop
else
nop
end
)
(func $possibly-null/testLogicalOrMulti (; 16 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
@ -185,6 +188,10 @@
nop
end
)
(func $null (; 17 ;) (type $FUNCSIG$v)
(func $possibly-null/testAssign (; 17 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
local.get $1
local.set $0
)
(func $null (; 18 ;) (type $FUNCSIG$v)
)
)