summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/vm/node.lua8
-rw-r--r--script/vm/runner.lua32
-rw-r--r--test/type_inference/init.lua47
3 files changed, 65 insertions, 22 deletions
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 204a149d..d3e407b6 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -10,6 +10,7 @@ vm.nodeCache = {}
---@field [integer] vm.object
local mt = {}
mt.__index = mt
+mt.id = 0
mt.type = 'vm.node'
mt.optional = nil
mt.lastInfer = nil
@@ -273,11 +274,16 @@ function vm.clearNodeCache()
vm.nodeCache = {}
end
+local ID = 0
+
---@param a? vm.node | vm.object
---@param b? vm.node | vm.object
---@return vm.node
function vm.createNode(a, b)
- local node = setmetatable({}, mt)
+ ID = ID + 1
+ local node = setmetatable({
+ id = ID,
+ }, mt)
if a then
node:merge(a)
end
diff --git a/script/vm/runner.lua b/script/vm/runner.lua
index 0d8d023e..2be187c9 100644
--- a/script/vm/runner.lua
+++ b/script/vm/runner.lua
@@ -72,35 +72,29 @@ function mt:_compileNarrowByFilter(filter, outStep, blockStep)
self:_compileNarrowByFilter(filter[2], outStep, blockStep)
end
if filter.op.type == 'or' then
- local orRightStep = {
+ local dummyStep = {
type = 'load',
- tag = 'orRight',
+ tag = 'dummy',
copy = true,
ref1 = outStep,
pos = filter.start - 1,
}
- local orLeftStep = {
+ self.steps[#self.steps+1] = dummyStep
+ self:_compileNarrowByFilter(filter[1], outStep, dummyStep)
+ dummyStep = {
type = 'load',
- tag = 'orLeft',
+ tag = 'dummy',
copy = true,
ref1 = outStep,
- pos = filter.start - 1,
- }
- self.steps[#self.steps+1] = orRightStep
- self.steps[#self.steps+1] = orLeftStep
- self:_compileNarrowByFilter(filter[1], orRightStep, orLeftStep)
- self.steps[#self.steps+1] = {
- type = 'load',
- tag = 'orReset',
- ref1 = orRightStep,
- pos = filter.op.start
+ pos = filter.op.finish,
}
- self:_compileNarrowByFilter(filter[2], orLeftStep, orRightStep)
+ self.steps[#self.steps+1] = dummyStep
+ self:_compileNarrowByFilter(filter[2], outStep, dummyStep)
self.steps[#self.steps+1] = {
type = 'load',
tag = 'reset',
ref1 = blockStep,
- pos = filter.finish
+ pos = filter.finish,
}
end
if filter.op.type == '=='
@@ -339,11 +333,7 @@ function mt:launch(callback)
elseif step.type == 'save' then
step.node = node
elseif step.type == 'load' then
- if step.ref1 then
- step.node = step.ref1.node
- else
- step.node = node
- end
+ step.node = node
context = step
elseif step.type == 'merge' then
node:merge(step.ref2.node)
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 41ec3df7..df1f538b 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -1965,3 +1965,50 @@ local x
if not x or <?x?> then
end
]]
+
+TEST 'integer?' [[
+---@type integer?
+local x
+
+if not x or XXX then
+ print(<?x?>)
+end
+]]
+
+TEST 'integer?' [[
+---@type integer?
+local x
+
+if x or XXX then
+ print(<?x?>)
+end
+]]
+
+TEST 'integer?' [[
+---@type integer?
+local x
+
+if XXX or x then
+ print(<?x?>)
+end
+]]
+
+TEST 'integer?' [[
+---@type integer?
+local x
+
+if XXX or not x then
+ print(<?x?>)
+end
+]]
+
+TEST 'integer' [[
+---@type integer?
+local x
+
+if not x or XXX then
+ return
+end
+
+print(<?x?>)
+]]