Skip to content

Commit

Permalink
fix error when handling index with a non-literal key. eg: t[#t+1] = true
Browse files Browse the repository at this point in the history
  • Loading branch information
xebecnan committed Nov 4, 2021
1 parent 14ffdab commit 601d799
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/symbols.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,18 @@ local function find_symbol(namespace, ast, narrow_func)
return { tag='Id', 'Any' }
end

local Types = require('types')
local field_type = Types.get_node_type(ast[2])
if field_type.tag == 'Id' and field_type[1] == 'Any' then
return { tag='Id', 'Any' }
elseif field_type.tag == 'Id' and field_type[1] == 'Str' then
-- literal string as index
assert(ast[2].tag == 'Str')
if ast[2].tag == 'Str' then
local key = ast[2][1]
return get_table_field(si1, key)
elseif field_type.tag == 'Id' and field_type[1] == 'Integer' then
-- literal integer as index
assert(ast[2].tag == 'Integer')
elseif ast[2].tag == 'Integer' then
local key = ast[2][1]
return get_table_field(si1, key)
end

local Types = require('types')
local field_type = Types.get_node_type(ast[2])
if field_type.tag == 'Id' and field_type[1] == 'Any' then
return { tag='Id', 'Any' }
else
-- TODO: 其他类型作为 key
ast_error(ast, "find_symbol not support '%s' yet: TODO", Types.get_full_type_name(field_type, false))
Expand Down

0 comments on commit 601d799

Please sign in to comment.