LuaLS / LuaLS/lua-language-server

Type warning when calling os.time with a table

Open
#2,475 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feat/type check
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### 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

### Expected Behaviour

No warning

### Actual Behaviour

The following warning is appearing:

Cannot assign `string|osdate` to parameter `osdateparam?`.
- `string` cannot match `osdateparam?`
- Type `string` cannot match `nil`
- Type `string` cannot match `osdateparam`

### Reproduction steps

1. Enter the following code
```
local tDate = os.date("*t", os.time())
-- tDate is a table, e.g. {year=2024, month=1, day=10, hour=13, min=2, sec=24, yday=10, wday=4, isdst=false}
local newTime = os.time(tDate)
```
2. Linter warning appears in the _problems_ tab

### Additional Notes

_No response_

### Log File

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning in the Visual Studio Code extension with the Lua snippet from the issue, focusing on the os.date and os.time calls. Trace the type information used for os.time and verify that passing the table returned by os.date("*t", os.time()) is accepted without a type-checking warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.