Skip to content

fix: use return_overload annotations in std libs, to fix overload return type inference - #1030

Merged
CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
EfveZombie:fix.overload_fail
Apr 13, 2026
Merged

CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
EfveZombie:fix.overload_fail

Conversation

@EfveZombie

Copy link
Copy Markdown

Summary

Replace ---@return type? patterns with ---@return_overload annotations in standard library definitions, to fix overload return type inference for functions that return either a success value or nil, error_message.

Changed files

  • global.lua: load, loadstring, loadfile
  • io.lua: io.open, io.write, file:close, file:flush, file:seek, file:write
  • package.lua: package.searchpath
  • utf8.lua: utf8.len

Motivation

The previous ---@return type? annotations merged all return values into a single nullable type, which caused the type checker to lose overload information. By using ---@return_overload, each return variant is expressed as a distinct overload, allowing the analyzer to correctly narrow types based on success/failure branches.

@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 Lua standard library annotations by replacing @return tags with @return_overload in global.lua, io.lua, package.lua, and utf8.lua. A review comment points out that package.searchpath was incorrectly modified to return a file object instead of a string, which is a regression from the previous state.

…urn type inference for functions like load, io.open, etc.
@CppCXY
CppCXY merged commit bf9e36e into EmmyLuaLs:main Apr 13, 2026
16 checks passed
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