diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/config/template.lua | 1 | ||||
-rw-r--r-- | script/utility.lua | 4 | ||||
-rw-r--r-- | script/vm/type.lua | 12 |
3 files changed, 8 insertions, 9 deletions
diff --git a/script/config/template.lua b/script/config/template.lua index c7162012..3d5bad3d 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -366,6 +366,7 @@ local template = { ['Lua.misc.parameters'] = Type.Array(Type.String), ['Lua.type.castNumberToInteger'] = Type.Boolean >> false, ['Lua.type.weakUnionCheck'] = Type.Boolean >> false, + ['Lua.type.weakNilCheck'] = Type.Boolean >> false, -- VSCode ['files.associations'] = Type.Hash(Type.String, Type.String), diff --git a/script/utility.lua b/script/utility.lua index 034f19d5..e7aabaca 100644 --- a/script/utility.lua +++ b/script/utility.lua @@ -275,7 +275,7 @@ local function sortTable(tbl) end --- 创建一个有序表 ----@param tbl table {optional = 'self'} +---@param tbl? table ---@return table function m.container(tbl) return sortTable(tbl) @@ -570,7 +570,7 @@ end ---遍历文本的每一行 ---@param text string ---@param keepNL? boolean # 保留换行符 ----@return fun(text:string):string, integer +---@return fun():string, integer function m.eachLine(text, keepNL) local offset = 1 local lineCount = 0 diff --git a/script/vm/type.lua b/script/vm/type.lua index 399cbffc..ac3b8986 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -62,20 +62,18 @@ function vm.isSubType(uri, child, parent, mark) return true end end - if child:isOptional() then - if vm.isSubType(uri, 'nil', parent, mark) then - return true - end - end return false else + local weakNil = config.get(uri, 'Lua.type.weakNilCheck') for n in child:eachObject() do - if getNodeName(n) + local nodeName = getNodeName(n) + if nodeName + and not (nodeName == 'nil' and weakNil) and not vm.isSubType(uri, n, parent, mark) then return false end end - if child:isOptional() then + if not weakNil and child:isOptional() then if not vm.isSubType(uri, 'nil', parent, mark) then return false end |