Skip to content

Commit 08b9dd3

Browse files
committed
cleanup
1 parent 9ad317f commit 08b9dd3

File tree

16 files changed

+70
-31
lines changed

16 files changed

+70
-31
lines changed

locale/zh-cn/script.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ DIAG_PARAM_TYPE_MISMATCH =
127127
DIAG_UNKNOWN_CAST_VARIABLE =
128128
'未知的类型转换变量 `{}`。'
129129
DIAG_CAST_TYPE_MISMATCH =
130-
'不能将 `{ref}` 转换为 `{def}`。'
130+
'不能将 `{def}` 转换为 `{ref}`。'
131131
DIAG_MISSING_RETURN_VALUE =
132132
'至少需要 {min} 个返回值,但此处只返回 {rmax} 个值。'
133133
DIAG_MISSING_RETURN_VALUE_RANGE =

script/core/diagnostics/cast-type-mismatch.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ return function (uri, callback)
3030
callback {
3131
start = cast.extends.start,
3232
finish = cast.extends.finish,
33-
message = lang.script('DIAG_UNKNOWN_CAST_VARIABLE', {
33+
message = lang.script('DIAG_CAST_TYPE_MISMATCH', {
3434
def = vm.getInfer(defNode):view(uri),
3535
ref = vm.getInfer(refNode):view(uri),
3636
})

script/files.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ function m.isLibrary(uri, excludeFolder)
136136
end
137137

138138
--- 获取库文件的根目录
139+
---@return uri?
139140
function m.getLibraryUri(suri, uri)
140141
local scp = scope.getScope(suri)
141142
return scp:getLinkedUri(uri)

script/vm/compiler.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ end
400400
---@field _sign vm.sign|false
401401

402402
---@param source parser.object
403-
---@return vm.sign?
403+
---@return vm.sign|false
404404
local function getObjectSign(source)
405405
if source._sign ~= nil then
406406
return source._sign
@@ -1542,7 +1542,7 @@ local compilerSwitch = util.switch()
15421542
end)
15431543
end
15441544
if hasGeneric then
1545-
---@cast sign -?
1545+
---@cast sign -false
15461546
vm.setNode(source, vm.createGeneric(rtn, sign))
15471547
else
15481548
vm.setNode(source, vm.compileNode(rtn))
@@ -1955,7 +1955,9 @@ function vm.compileNode(source)
19551955

19561956
if source.type == 'generic' then
19571957
vm.setNode(source, source)
1958-
return vm.getNode(source)
1958+
local node = vm.getNode(source)
1959+
---@cast node -?
1960+
return node
19591961
end
19601962

19611963
---@cast source parser.object
@@ -1965,6 +1967,6 @@ function vm.compileNode(source)
19651967
matchCall(source)
19661968

19671969
local node = vm.getNode(source)
1968-
1970+
---@cast node -?
19691971
return node
19701972
end

script/vm/function.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ end
1818

1919
---@param func parser.object
2020
---@return integer min
21-
---@return integer max
21+
---@return number max
2222
function vm.countParamsOfFunction(func)
2323
local min = 0
2424
local max = 0
@@ -60,7 +60,7 @@ end
6060

6161
---@param node vm.node
6262
---@return integer min
63-
---@return integer max
63+
---@return number max
6464
function vm.countParamsOfNode(node)
6565
local min, max
6666
for n in node:eachObject() do
@@ -82,15 +82,21 @@ end
8282
---@param func parser.object
8383
---@param mark? table
8484
---@return integer min
85-
---@return integer max
85+
---@return number max
8686
function vm.countReturnsOfFunction(func, mark)
8787
if func.type == 'function' then
88-
local min, max
88+
---@type integer?
89+
local min
90+
---@type number?
91+
local max
8992
local hasDocReturn
9093
if func.bindDocs then
9194
local lastReturn
9295
local n = 0
93-
local dmin, dmax
96+
---@type integer?
97+
local dmin
98+
---@type number?
99+
local dmax
94100
for _, doc in ipairs(func.bindDocs) do
95101
if doc.type == 'doc.return' then
96102
hasDocReturn = true
@@ -139,10 +145,12 @@ end
139145
---@param func parser.object
140146
---@param mark? table
141147
---@return integer min
142-
---@return integer max
148+
---@return number max
143149
function vm.countReturnsOfCall(func, args, mark)
144150
local funcs = vm.getMatchedFunctions(func, args)
151+
---@type integer?
145152
local min
153+
---@type number?
146154
local max
147155
for _, f in ipairs(funcs) do
148156
local rmin, rmax = vm.countReturnsOfFunction(f, mark)
@@ -159,7 +167,7 @@ end
159167
---@param list parser.object[]?
160168
---@param mark? table
161169
---@return integer min
162-
---@return integer max
170+
---@return number max
163171
function vm.countList(list, mark)
164172
if not list then
165173
return 0, 0

script/vm/generic.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mt.type = 'generic'
1313

1414
---@param source vm.object
1515
---@param resolved? table<string, vm.node>
16-
---@return parser.object
16+
---@return vm.object
1717
local function cloneObject(source, resolved)
1818
if not resolved then
1919
return source

script/vm/local-id.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function compileLocalID(source)
147147
end
148148

149149
---@param source parser.object
150-
---@return string?
150+
---@return string|false
151151
function vm.getLocalID(source)
152152
if source._localID ~= nil then
153153
return source._localID
@@ -205,7 +205,7 @@ end
205205

206206
---@param source parser.object
207207
---@param includeGets boolean
208-
---@return parser.object[]
208+
---@return parser.object[]?
209209
function vm.getLocalFields(source, includeGets)
210210
local id = vm.getLocalID(source)
211211
if not id then

script/vm/node.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function mt:clear()
6262
end
6363

6464
---@param n integer
65-
---@return vm.object?
65+
---@return vm.node.object?
6666
function mt:get(n)
6767
return self[n]
6868
end
@@ -284,7 +284,8 @@ function mt:removeNode(node)
284284
self:remove(c.name)
285285
elseif c.type == 'nil' then
286286
self:remove 'nil'
287-
elseif c.type == 'boolean' then
287+
elseif c.type == 'boolean'
288+
or c.type == 'doc.type.boolean' then
288289
if c[1] == true then
289290
self:remove 'true'
290291
else

script/vm/runner.lua

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,20 @@ end
117117
---@return vm.node outNode
118118
function mt:_lookInto(action, topNode, outNode)
119119
if not action then
120-
return topNode, outNode
120+
return topNode, outNode or topNode
121121
end
122122
if self._mark[action] then
123-
return topNode, outNode
123+
return topNode, outNode or topNode
124124
end
125125
self._mark[action] = true
126126
local top = self._objs[self._index]
127127
if not top then
128-
return topNode, outNode
128+
return topNode, outNode or topNode
129129
end
130130
if not guide.isInRange(action, top.finish)
131131
-- trick for `local tp = type(x);if tp == 'string' then`
132132
and action.type ~= 'binary' then
133-
return topNode, outNode
133+
return topNode, outNode or topNode
134134
end
135135
local set
136136
local value = vm.getObjectValue(action)
@@ -151,7 +151,9 @@ function mt:_lookInto(action, topNode, outNode)
151151
self:_fastWard(action.filter.finish, blockNode)
152152
end
153153
blockNode = self:_launchBlock(action, blockNode:copy())
154-
topNode = mainNode:merge(blockNode)
154+
if mainNode then
155+
topNode = mainNode:merge(blockNode)
156+
end
155157
elseif action.type == 'if' then
156158
local hasElse
157159
local mainNode = topNode:copy()
@@ -314,7 +316,7 @@ function mt:_lookInto(action, topNode, outNode)
314316
if set then
315317
topNode = self:_fastWard(set.range or set.finish, topNode)
316318
end
317-
return topNode, outNode
319+
return topNode, outNode or topNode
318320
end
319321

320322
---@param block parser.object
@@ -356,7 +358,10 @@ function vm.launchRunner(loc, callback)
356358
if #self._objs == 0 then
357359
return
358360
end
359-
360-
local topNode = self:_launchBlock(guide.getParentBlock(loc), vm.getNode(loc):copy())
361+
local main = guide.getParentBlock(loc)
362+
if not main then
363+
return
364+
end
365+
local topNode = self:_launchBlock(main, vm.getNode(loc):copy())
361366
self:_fastWard(math.maxinteger, topNode)
362367
end

script/vm/sign.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717
---@param uri uri
1818
---@param args parser.object
1919
---@param removeGeneric true?
20-
---@return table<string, vm.node>
20+
---@return table<string, vm.node>?
2121
function mt:resolve(uri, args, removeGeneric)
2222
if not args then
2323
return nil

0 commit comments

Comments
 (0)