Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
* `FIX` LuaJIT nil-coalescing `??` now strips the optional `?` from the left-hand type (e.g. `integer? ?? 2` infers `integer`) [#3459](https://github.com/LuaLS/lua-language-server/issues/3459)
* `FIX` A `.gitignore` line containing only whitespace no longer ignores the entire workspace [#3458](https://github.com/LuaLS/lua-language-server/issues/3458)
* `FIX` `need-check-nil` diagnostic is no longer reported on safe navigation access (e.g. `x?.field`, `f?.()`, `t?.[key]`), since the optional access itself already handles the nil check. Note that a non-safe access chained after a safe one (e.g. `x.upper()?.field`) still reports, because the safe access only protects its own result.

Expand Down
2 changes: 1 addition & 1 deletion script/vm/operator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ vm.binarySwitch = util.switch()
local node2 = vm.compileNode(source[2])
-- 统计具体类型:variable/local 是引用元信息,无具体类型时视为未知(可能为 nil)
local count = 0
local hasNil = false
local hasNil = node1:isOptional()
for c in node1:eachObject() do
if c.type == 'nil'
or (c.type == 'global' and c.cate == 'type' and c.name == 'nil') then
Expand Down
8 changes: 8 additions & 0 deletions test/type_inference/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,14 @@ end
local <?x?> = n or 0
]]

config.set(nil, 'Lua.runtime.nonstandardSymbol', { '??' })
TEST 'integer' [[
---@type integer?
local foo = 1
local <?bar?> = foo ?? 2
]]
config.set(nil, 'Lua.runtime.nonstandardSymbol', {})

TEST 'number' [=[
local <?x?> = F()--[[@as number]]
]=]
Expand Down
Loading