pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.6k stars 519 forks source link

Analyzer Error #1093

Closed qgenesist closed 3 years ago

qgenesist commented 3 years ago

Windows 10 up to date. Zerobrane 1.80

error is: luainspect\init.lua:723 bad arg #1 to next. table expected, got function.

**CODE: for k, v in pairs(_G) do local kt = k local vt = v local kn = tostring(k) local vn = tostring(v) if tostring(k) ~= '_G' then

if type(v) == 'table' then
  for i, x in pairs(vt) do
    print('k: ', tostring(kn), '  ', 'i: ', type(i), '  ', tostring(i), '  ', 'x:', type(x), '  ', tostring(x))
  end
else
  print('k: ', type(k), '  ', tostring(k), '  ', 'v:', type(v), '  ', tostring(v))
end

end end

return

I am simply going thru the table _G and indexing functions and methods to their 'pointers', if I find a table of functions or methods in the table _G, I unroll them. I am using Family Historian which is lua 5.1 and it runs sucessfully in it, but the Analyze in ZB doesn't find it one bit funny.

pkulchenko commented 3 years ago

Is this the entire code you are analyzing? I don't get any error using 1.80 (I copied your code from **CODE up to and including return)?

qgenesist commented 3 years ago

Yes PaulK, that is all.

for k, v in pairs(_G) do local kt = k local vt = v local kn = tostring(k) local vn = tostring(v) if tostring(k) ~= '_G' then

if type(v) == 'table' then for i, x in pairs(vt) do print('k: ', tostring(kn), ' ', 'i: ', type(i), ' ', tostring(i), ' ', 'x:', type(x), ' ', tostring(x)) end else print('k: ', type(k), ' ', tostring(k), ' ', 'v:', type(v), ' ', tostring(v)) end

end end

return

I would copy the stack window. but it is not copyable.

I am w10 64 bit. Analyze button on the ribbon gives the error. it indents correctly from > correct indentation, which it usually does not if there is a logic error or line error. something somewhere is amiss.

here is my prefs if it helps

--[[-- Use this file to specify User preferences. Review examples or check online documentation for details. --]]-- autoanalyzer = true console.fontname = 'Courier New' console.fontsize = 10 default.extension = 'lua' filetree.showchanges = true

local luaspec = ide.specs.lua luaspec.exts[#luaspec.exts + 1] = 'fh_lua'

editor.autoreload = true editor.fontname = 'Courier New' editor.fontsize = 12 editor.specmap.fh_lua = 'lua' editor.specmap.wlua = 'lua'

editor.tabwidth = 2 editor.smartindent = true editor.indentguide = wxstc.wxSTC_IV_LOOKBOTH --prf editor.wrapindentmode = wxstc.wxSTC_WRAPINDENT_INDENT --prf

pkulchenko commented 3 years ago

Hm, I can't reproduce this on either 1.80, 1.90, or the current master, even with the same config.

I would copy the stack window. but it is not copyable.

Can you include the screenshot of the stack trace?

Analyze button on the ribbon gives the error.

I don't think there is an analyze button on the toolbar in the default configuration. Are you using some plugins in your setup?

qgenesist commented 3 years ago

Untitled

Project>Analyze I wouldnt know if I use plugins, it is straightforward choices from the dropdowns, and since I dont know if I do, I probably don't. How would I know, there is no install plugins I can see, and I looked at doing the fh api interface xml file, but it seemed rather daunting from text to file. so I put up with the unknown warnings and pick thru them.

qgenesist commented 3 years ago

ok, fixed the close

pkulchenko commented 3 years ago

@qgenesist, can you try the following patch (you can apply this change manually):

diff --git a/lualibs/luainspect/init.lua b/lualibs/luainspect/init.lua
index bab48fa1..9b643531 100644
--- a/lualibs/luainspect/init.lua
+++ b/lualibs/luainspect/init.lua
@@ -719,7 +719,7 @@ function M.infer_values(top_ast, tokenlist, src, report)
         local t_ast = iter_ast[1][2]
         local value = T.universal
         local key
-        if t_ast.value and (known(t_ast.value) or T.istabletype[t_ast.value]) then
+        if t_ast.value and T.istabletype[t_ast.value] then
           key = next(t_ast.value)
           local ok; ok, value = pzcall(tindex, {t_ast, {tag='String', key}}, t_ast.value, key)
           if not ok then value = T.error(t_ast.value) end

I'm not sure why I'm not able to reproduce this issue, but this may fix it.

qgenesist commented 3 years ago

lol, you think more of me than you should PaulK.

removed: if t_ast.value and (known(t_ast.value) or T.istabletype[t_ast.value]) then inserted: if t_ast.value and T.istabletype[t_ast.value] then

Compilation error on line 926: C:\ProgramData\ZeroBraneStudio\lualibs\luainspect\init.lua:926: unexpected symbol near ')'

917 elseif ast.tag == 'While' then -- detect dead-code if DETECT_DEADCODE then local expr_ast, body_ast = ast[1], ast[2] if T.boolean_cast(expr_ast.value) == false then mark_dead(body_ast) end end end 926 end) 027 end

numbers at left are mine for your reference

qgenesist commented 3 years ago

dont know what happened, didnt save it. went into zerobrane again and replaced one line. this time it compiled and analyzed init. now, I will try to exit, go back in fresh, and give you an update

qgenesist commented 3 years ago

that fixed that error. it now analyzes. Thanks. do you close them normally or I?

pkulchenko commented 3 years ago

I'll close it when I check in the fix; thank you.

qgenesist commented 3 years ago

thank you.

qgenesist commented 3 years ago

fyi it did the bigger nest (I have one more to go)

require('_STD_SAVRST')

local xlat = {}

function rslv_fn_ptr() for k, v in pairs(_G) do local kn = tostring(k) local vn = tostring(v) local vt = v if tostring(k) ~= '_G' then

if type(v) == 'table' then
  for w, x in pairs(vt) do
    local wn = tostring(w)
    local xn = tostring(x)
    local xt = x
    if type(x) == 'table' then
      for y, z in pairs(xt) do
        local yn = tostring(y)
        local zn = tostring(z)
        local zt = z
        print('ptr: ', tostring(z), ' fn: ', (kn.. ':' .. wn .. '.' .. tostring(y)), '  ',  type(w))
        table.insert(xlat, 
          {
            ptr = tostring(z):gsub('function: ', ''),
            fn = (kn.. ':' .. wn .. '.' .. tostring(y)),
          }
        )
      end
    else
      print('ptr: ', tostring(x), ' fn: ', (kn .. ':'.. wn), '  ', type(w))
      table.insert(xlat,
        {
          ptr = tostring(x):gsub('function: ', ''),
          fn = (kn.. ':' .. wn),
        }
      )
    end
  end
else
  print('ptr: ', tostring(v),  ' fn: ', tostring(k), '  ', type(k))
  table.insert(xlat,
    {
      ptr = tostring(v):gsub('function: ', ''), 
      fn = tostring(k),
    }
  )
end

end end end -- rslv_fn_ptr

xlat, _fp = rtvTBL('xlat', '*global') xlat = {} rslv_fn_ptr() save(xlat, _fp)

return the require _STD_SAVRST contains some slightly modified chillcode from lua users. a way to retrieve a table from disk, saved earlier, or empty if not on disk: RTVTBL(file, filepath) and save: save(table, filepath) note that I get the file off the disk and clear the table anyhow (for testing) but I nested three tables deep so far, it works.

pkulchenko commented 3 years ago

@qgenesist, it looks like this error requires staticanalyzer.infervalue = true to be set in the config (and that's why I wasn't able to reproduce it. It's not shown in the config you sent me, but maybe it's in another config (check both the system and the user one in Edit > Preferences). The patch should fix it (as you already confirmed).