Skip to content

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

Open
EfveZombie wants to merge 1 commit intoEmmyLuaLs:mainfrom
EfveZombie:fix.overload_fail
Open

fix: use return_overload annotations in std libs, to fix overload return type inference#1030
EfveZombie wants to merge 1 commit intoEmmyLuaLs: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.

Copy link
Copy Markdown
Contributor

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

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

1 participant