Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom __pairs expects only 1 return value #2512

Open
oezingle opened this issue Feb 6, 2024 · 0 comments
Open

Custom __pairs expects only 1 return value #2512

oezingle opened this issue Feb 6, 2024 · 0 comments

Comments

@oezingle
Copy link

oezingle commented Feb 6, 2024

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Type Checking

Expected Behaviour

I expected no warnings

Actual Behaviour

There is a redundant return value warning

Reproduction steps

Here's an example where string paths are transformed to their package.loaded value

local imports = {
    mod1 = "src.mod1",
    mod2 = "src.mod2"
}

return setmetatable({}, {
    __pairs = function(_)
        local iter = pairs(imports)

        local newiter = function (table, index) 
            local k, path = iter(table, index)

            return k, package.loaded[path]
        end

        --- LuaLS is wrong here
        ---@diagnostic disable-next-line:redundant-return-value
        return newiter, imports, nil
    end
})

Additional Notes

https://www.lua.org/pil/7.3.html

Log File

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant