IntelliJ-Luanalysis
IntelliJ-Luanalysis copied to clipboard
Luanalysis doesn't seem to understand manual nil check
Environment
Name | Version |
---|---|
IDEA version | 2023.1.3 |
Luanalysis version | 1.4.0 |
OS | Windows 10 |
Preferences
Lua
Name | Setting |
---|---|
Language level | Lua 5.4 |
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?
---@type string[] | nil
local strs = {"abc"}
if strs ~= nil then
print(strs[1])
end
What happens?
Error: No such indexer '[1] found on type 'nil'
What were you expecting to happen?
No error.
Any other comments?
I'm not sure if it's intentional or not, but I think it should report error in this case. For example, in C#, if we do manual null check first:
private string? _str = null;
...
if(_str != null)
{
_str.ToUpper();
}
It'll compile without problem.
Furthermore, what's the alternative? Put --[[---@not nil]]
everywhere?