Skip to content

need-check-nil warning for arr[#arr] after length check #878

@Yoctillion

Description

@Yoctillion

After checking the length of arr, emmylua will still report a need-check-nil warning when using arr[#arr]

Example

---@class Foo
---@field bar number

---@type Foo[]
local arr = {}
if #arr > 0 then
    local v = arr[#arr].bar  -- Warning: arr[#arr] may be nil
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions