Skip to content

Incorrect generic inference on function return #1111

Closed

Description

@sharpchen
---@generic T
---@param fov (fun(...): T | nil)
---@param ... unknown params for function
---@return T | nil
---@overload fun(fov: T): T
function fn_or_val(fov, ...) return type(fov) == 'function' and fov(...) or fov end

local fn = function() return math.random() > 0.5 and 'foo' or nil end

-- foo is expected to be string?
-- but inferred as fun() -> "foo"?
local foo = fn_or_val(fn)

-- inferred as string, correct
local bar = fn_or_val('foo')

Activity

  1. self-assigned this
    on Jun 18, 2026
  2. added a commit that references this issue on Jun 18, 2026
    57c6731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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