summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/parser/guide.lua2
-rw-r--r--script/vm/compiler.lua8
-rw-r--r--script/vm/node.lua11
-rw-r--r--test/type_inference/init.lua13
4 files changed, 32 insertions, 2 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index d47d0034..1e994775 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -10,7 +10,7 @@ local type = type
---@field type string
---@field special string
---@field tag string
----@field args parser.object[]
+---@field args { [integer]: parser.object, start: integer, finish: integer }
---@field locals parser.object[]
---@field returns parser.object[]
---@field exps parser.object[]
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 103239c1..dd41d7b6 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -641,7 +641,12 @@ local function compileByLocalID(source)
if src.value then
if not hasMarkDoc or guide.isLiteral(src.value) then
if src.value.type ~= 'nil' then
- vm.setNode(source, vm.compileNode(src.value))
+ local valueNode = vm.compileNode(src.value)
+ if valueNode:hasType 'unknown' then
+ vm.setNode(source, valueNode:copy():remove 'unknown')
+ else
+ vm.setNode(source, valueNode)
+ end
end
end
end
@@ -1296,6 +1301,7 @@ local compilerSwitch = util.switch()
return
end
compileByLocalID(source)
+ ---@type string|vm.node
local key = guide.getKeyName(source)
if key == nil and source.index then
key = vm.compileNode(source.index)
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 39ed219e..1ff229fa 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -269,6 +269,17 @@ function mt:removeNode(node)
end
end
+---@param name string
+---@return boolean
+function mt:hasType(name)
+ for _, c in ipairs(self) do
+ if c.type == 'global' and c.cate == 'type' and c.name == name then
+ return true
+ end
+ end
+ return false
+end
+
---@return fun():vm.object
function mt:eachObject()
local i = 0
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 09f51b8e..aa424d9c 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -2674,3 +2674,16 @@ local t
local <?x?> = t.x
]]
+
+TEST 'integer' [[
+local function f()
+ return GG
+end
+
+local t
+
+t.x = 1
+t.x = f()
+
+print(t.<?x?>)
+]]