IntelliJ-Luanalysis icon indicating copy to clipboard operation
IntelliJ-Luanalysis copied to clipboard

Allow custom function definitions in table

Open nlebedenco opened this issue 2 years ago • 0 comments

Environment

Name Version
IDEA version CL2022.3.2
Luanalysis version v1.4.0
OS Windows 10

Lua

Name Setting
Language level Lua 5.1

Type Safety

Name Setting
Strict nil checks
Unknown type (any) is indexable ☑️
Unknown type (any) is callabale ☑️

What are the steps to reproduce this issue?

  1. Add a def file to the project declaring custom functions in the global table module. For example:
--- Creates a pre-sized table, just like the C API equivalent
--- `lua_createtable`. This is useful for big tables if the final table size is
--- known and automatic table resizing is too expensive.
---@overload fun(narr:number):table
---@param narr number
---@param nrec number
---@return table
function table.new(narr, nrec) end

--- Clears all keys and values from a table, but preserves the allocated array/hash sizes.
--- This is useful when a table, which is linked from
--- multiple places, needs to be cleared and/or when recycling a table for use
--- by the same context. This avoids managing backlinks, saves an allocation
--- and the overhead of incremental array/hash part growth.
---
--- Please note, this function is meant for very specific situations. In most
--- cases it's better to replace the (usually single) link with a new table
--- and let the GC do its work.
---@param t table
function table.clear(t) end

What happens?

Custom function definitions are ignored and uses are reported as errors.

What were you expecting to happen?

Custom function definitions should be merged with the std definitions as is the case for example with the math module.

Any other comments?

The "table" type is not the same thing as the "table" module and this is an important distinction. As far as the module goes it could have been given a different name altogether like "container" just as the "math" module is not called "number". It just happens that the type and the module share the same name in this case. Also consider that many lua frameworks add custom functions to std modules as extensions (for example, Premake) which causes a lot of false errors to be reported.

nlebedenco avatar Jan 29 '23 04:01 nlebedenco