summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/files.lua4
-rw-r--r--script/parser/guide.lua16
-rw-r--r--script/vm/infer.lua2
-rw-r--r--test/type_inference/init.lua24
4 files changed, 39 insertions, 7 deletions
diff --git a/script/files.lua b/script/files.lua
index 3b2b120b..f3a11185 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -15,6 +15,7 @@ local encoder = require 'encoder'
local scope = require 'workspace.scope'
---@class file
+---@field uri uri
---@field content string
---@field _ref? integer
---@field trusted? boolean
@@ -148,6 +149,9 @@ function m.exists(uri)
return m.fileMap[uri] ~= nil
end
+---@param file file
+---@param text string
+---@return string
local function pluginOnSetText(file, text)
local plugin = require 'plugin'
file._diffInfo = nil
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index cb10efa2..b783a9e1 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -1090,16 +1090,20 @@ function m.getPath(a, b, sameFunction)
local pathB = {}
for _ = 1, 1000 do
objA = m.getParentBlock(objA)
- pathA[#pathA+1] = objA
- if (not sameFunction and objA.type == 'function') or objA.type == 'main' then
- break
+ if objA then
+ pathA[#pathA+1] = objA
+ if (not sameFunction and objA.type == 'function') or objA.type == 'main' then
+ break
+ end
end
end
for _ = 1, 1000 do
objB = m.getParentBlock(objB)
- pathB[#pathB+1] = objB
- if (not sameFunction and objA.type == 'function') or objB.type == 'main' then
- break
+ if objB then
+ pathB[#pathB+1] = objB
+ if (not sameFunction and objB.type == 'function') or objB.type == 'main' then
+ break
+ end
end
end
-- pathA: {1, 2, 3, 4, 5}
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index 1f77b638..d30ba36c 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -433,7 +433,7 @@ function mt:viewLiterals()
or n.type == 'integer'
or n.type == 'boolean' then
local literal = util.viewLiteral(n[1])
- if not mark[literal] then
+ if literal and not mark[literal] then
literals[#literals+1] = literal
mark[literal] = true
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 37cf0324..cfb7d3a6 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -3281,3 +3281,27 @@ local b
local c = a and b
local <?d?> = a or b
]]
+
+TEST 'number' [[
+local x
+
+---@return number
+local function f()
+end
+
+x = f()
+
+print(<?x?>)
+]]
+
+TEST 'number' [[
+local x
+
+---@return number
+local function f()
+end
+
+_, x = pcall(f)
+
+print(<?x?>)
+]]