diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-28 15:16:10 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-28 15:16:10 +0800 |
commit | f72976a6fa20549afe91cdb8740d6bc59332ee92 (patch) | |
tree | 6f8b03dbfee40950f51ecea2ecd2729bbc7c5dbc /server/src/core/value.lua | |
parent | e25be4fc724d0cc56b12c6453426763c750a7dc7 (diff) | |
download | lua-language-server-f72976a6fa20549afe91cdb8740d6bc59332ee92.zip |
类型推导
Diffstat (limited to 'server/src/core/value.lua')
-rw-r--r-- | server/src/core/value.lua | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/server/src/core/value.lua b/server/src/core/value.lua index c0f8848d..35e59816 100644 --- a/server/src/core/value.lua +++ b/server/src/core/value.lua @@ -16,8 +16,11 @@ function mt:inference(tp, rate) if tp == '...' then error('Value type cant be ...') end - if not tp or tp == 'any' then - return + if not tp then + tp = 'nil' + end + if tp == 'any' then + rate = 0.0 end if not self._type then self._type = {} @@ -91,7 +94,7 @@ function mt:rawGetField(name, source) return nil end -function mt:_getMeta(name, source) +function mt:getMeta(name, source) if not self._meta then return nil end @@ -125,7 +128,7 @@ end function mt:getField(name, source, stack) local field = self:rawGetField(name, source) if not field then - local indexMeta = self:_getMeta('__index', source) + local indexMeta = self:getMeta('__index', source) if not indexMeta then return nil end @@ -143,17 +146,21 @@ end function mt:eachField(callback) if not self._child then - return + return nil end local mark = {} for _, childs in pairs(self._child) do for name, field in pairs(childs) do if not mark[name] then mark[name] = true - callback(name, field) + local res = callback(name, field) + if res ~= nil then + return res + end end end end + return nil end function mt:getDeclarat() |