Skip to content

fix(type): luajit coroutine.running() - #1027

Merged
CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
phanen:types
Apr 8, 2026
Merged

CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
phanen:types

Conversation

@phanen

@phanen phanen commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

It give warning "The current Lua version Lua JIT is not accessible; expected >= Lua 5.2."after debde573

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the version annotation for the coroutine.running function in the Lua standard library definitions to include JIT support for the Lua 5.1 signature. However, the review feedback points out that LuaJIT actually follows the Lua 5.2+ specification for this function, which returns two values rather than a single thread reference. To provide accurate type information, the JIT tag should be moved to the 5.2+ definition instead of being associated with the 5.1 version.

function coroutine.resume(co, val1, ...) end

---@version 5.1
---@version 5.1, JIT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In LuaJIT, coroutine.running() follows the Lua 5.2+ specification, returning two values: the running coroutine (which is the main thread rather than nil when called from the main thread) and a boolean indicating if it is the main thread.

By adding JIT to this definition, you are associating LuaJIT with the Lua 5.1 signature (returning a single thread? value). This provides incorrect type information for LuaJIT users.

To correctly resolve the version warning while providing accurate types, you should instead add JIT to the second definition of coroutine.running() at line 71 (e.g., ---@version > 5.2, JIT).

---@version 5.1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This don't seem true.

~ master ❯ rlwrap luajit
LuaJIT 2.1.1774896198 -- Copyright (C) 2005-2026 Mike Pall. https://luajit.org/
JIT: ON SSE3 SSE4.1 BMI2 fold cse dce fwd dse narrow loop abc sink fuse
> =coroutine.wrap(coroutine.running)()
thread: 0x7f0655af85c8

~ master ❯ lua5.5
Lua 5.5.0  Copyright (C) 1994-2025 Lua.org, PUC-Rio
> =coroutine.wrap(coroutine.running)()
stdin:1: unexpected symbol near '='
> coroutine.wrap(coroutine.running)()
thread: 0x5650ae7ede28  false
> 

@CppCXY
CppCXY merged commit ee55df9 into EmmyLuaLs:main Apr 8, 2026
16 checks passed
@phanen
phanen deleted the types branch April 14, 2026 08:50
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

Successfully merging this pull request may close these issues.

2 participants