Skip to content

Unknown Vararg indices when itterated #2906

@PennyJim

Description

@PennyJim

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

This is similar to #1355

When I try and itterate over a Vararg table, it'll be unable to determine the indexing value.

Actual Behaviour

My enabling of no-unknowns comes and bites me as the key is unknown.

Reproduction steps

---@param ... AnyType
function any(...)
  for key, value in pairs{...} do
    -- key is typed as an unknown instead of integer
    -- value is typed as AnyType
  end
end

Additional Notes

I've been told that there might be edge cases that are why this isn't how it currently works, but I thought I'd ask to at least find them out and learn more.

And if you are questioning why I'm using pairs instead of ipairs, that's because I'm modding in factorio with a deterministic pairs. It is actually faster than ipairs with functionally the same result, but with support for sparse arrays (this makes other Lua environments so sad to work with...).

Finally, I'm writing this at work in the morning before I forget, so I'm not being as thorough as I would prefer. I can absolutely get more information if requested.

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