Skip to content

Missing Completion in For Loop #1887

@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, Completion, Hover

Expected Behaviour

In the following example:

---@class A_Class
local A = { x = 5 }

function A:func()
    for i = 1, self.x do
        print(i)
    end

    self.y = 3
    self.y = self.y + 3
end

When hovering over self.x in the for loop or trying to use auto-completion there, I expect to get x as a suggestion with the type integer.

image

It should be exactly the same result as if the self.y = self.y + 3 line is commented out.

---@class A_Class
local A = { x = 5 }

function A:func()
    for i = 1, self.x do
        print(i)
    end

    self.y = 3
    --self.y = self.y + 3
end

Actual Behaviour

The type of self is lost, but only in the for statement. Auto completion doesn't suggest x either.

image

This only happens when the line self.y = self.y + 3 is not removed or commented out. If it is removed, everything works as expected.

Reproduction steps

  1. Try the code snippets above in VS Code in version 3.6.10 of the LuaLS extension.

Additional Notes

No response

Log File

Let me know if you need it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions