diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-29 15:12:43 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-29 15:12:43 +0800 |
commit | 5881d4846e20499d3dafe643f1a5fb355756ed7b (patch) | |
tree | 0990ad50a4ba1995a4ed3b0e26093906ffd41d0e /script | |
parent | f0522c026acbe08be716aa751b548602604eb3e9 (diff) | |
download | lua-language-server-5881d4846e20499d3dafe643f1a5fb355756ed7b.zip |
#686
Diffstat (limited to 'script')
-rw-r--r-- | script/core/infer.lua | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/script/core/infer.lua b/script/core/infer.lua index 034b1963..58308857 100644 --- a/script/core/infer.lua +++ b/script/core/infer.lua @@ -31,6 +31,12 @@ local function mergeTable(a, b) end end +local function isBaseType(source, mark) + return m.hasType(source, 'number', mark) + or m.hasType(source, 'integer', mark) + or m.hasType(source, 'string', mark) +end + local function searchInferOfUnary(value, infers, mark) local op = value.op.type if op == 'not' then @@ -38,19 +44,24 @@ local function searchInferOfUnary(value, infers, mark) return end if op == '#' then - infers['integer'] = true + if m.hasType(value[1], 'table', mark) + or m.hasType(value[1], 'string', mark) then + infers['integer'] = true + end return end if op == '-' then if m.hasType(value[1], 'integer', mark) then infers['integer'] = true - else + elseif isBaseType(value[1], mark) then infers['number'] = true end return end if op == '~' then - infers['integer'] = true + if isBaseType(value[1], mark) then + infers['integer'] = true + end return end end @@ -73,6 +84,7 @@ local function searchInferOfBinary(value, infers, mark) end return end + -- must return boolean if op == '==' or op == '~=' or op == '<' @@ -82,21 +94,31 @@ local function searchInferOfBinary(value, infers, mark) infers['boolean'] = true return end + -- check number if op == '<<' or op == '>>' or op == '~' or op == '&' or op == '|' then - infers['integer'] = true + if isBaseType(value[1], mark) + and isBaseType(value[2], mark) then + infers['integer'] = true + end return end if op == '..' then - infers['string'] = true + if isBaseType(value[1], mark) + and isBaseType(value[2], mark) then + infers['string'] = true + end return end if op == '^' or op == '/' then - infers['number'] = true + if isBaseType(value[1], mark) + and isBaseType(value[2], mark) then + infers['number'] = true + end return end if op == '+' @@ -107,7 +129,8 @@ local function searchInferOfBinary(value, infers, mark) if m.hasType(value[1], 'integer', mark) and m.hasType(value[2], 'integer', mark) then infers['integer'] = true - else + elseif isBaseType(value[1], mark) + and isBaseType(value[2], mark) then infers['number'] = true end return |