Skip to content

Commit 082327a

Browse files
committed
x = x or y -> truthy
1 parent 8e1ec50 commit 082327a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

script/vm/compiler.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,7 @@ local compilerSwitch = util.switch()
985985
elseif src.value
986986
and src.value.type == 'binary'
987987
and src.value.op and src.value.op.type == 'or'
988-
and src.value[1] and src.value[1].type == 'getlocal' and src.value[1].node == source
989-
and src.value[2] and guide.isLiteral(src.value[2]) then
988+
and src.value[1] and src.value[1].type == 'getlocal' and src.value[1].node == source then
990989
-- x = x or 1
991990
vm.setNode(src, vm.compileNode(src.value))
992991
else

test/type_inference/init.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,13 @@ TEST 'integer' [[
18411841
---@type integer?
18421842
local x
18431843
1844+
<?x?> = x or y
1845+
]]
1846+
1847+
TEST 'integer' [[
1848+
---@type integer?
1849+
local x
1850+
18441851
if not x then
18451852
return
18461853
end
@@ -1947,6 +1954,6 @@ TEST 'integer' [[
19471954
---@type integer?
19481955
local x
19491956
1950-
if x and <?x?>.y then
1957+
if x and <?x?> then
19511958
end
19521959
]]

0 commit comments

Comments
 (0)