Skip to content

Missing "need-check-nil" on self fields #2437

@firas-assaad

Description

@firas-assaad

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Type Checking, Diagnostics/Syntax Checking

Expected Behaviour

I expect both methods to report the "need check nil" diagnostic:

---@class Y
---@field z string

---@class X
---@field y Y?
local X = {}

function X:no_warning()
    print(self.y.z) -- no diagnostics
end

function X:warning()
    local y = self.y
    print(y.z) -- need-check-nil
end

Actual Behaviour

The potential problem is only reported when using a local variable.

Reproduction steps

Try the code above. and note how only the first method (no_warning) works without any diagnostics.

Additional Notes

No response

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions