Skip to content

Fix function not being a valid type for (...any) -> ...any annotations - #2725

Open
Companion wants to merge 1 commit into
luau-lang:masterfrom
Companion:fix/function-type-as-variadic-callable
Open

Fix function not being a valid type for (...any) -> ...any annotations#2725
Companion wants to merge 1 commit into
luau-lang:masterfrom
Companion:fix/function-type-as-variadic-callable

Conversation

@Companion

@Companion Companion commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Problem

The function primitive represents the set of all function types, but it is not currently accepted as a subtype of the (...any) -> ...any annotation:

(...any) -> ...any

This causes valid annotations to be rejected:

type fun = typeof((function()
    local value: unknown
    assert(typeof(value) == "function")
    return value
end)())

local value: fun = ...
local callable: (...any) -> ...any = value

This is distinct from #2656, which was closed as by design. That issue attempted to use function as a subtype of specific function signatures, which is unsafe and remains rejected:

Relation Result after this change
function <: () -> () Rejected
function <: (...any) -> () Rejected
function <: (...any) -> ...any Accepted
(number) -> string <: function Accepted, unchanged

Of these, only (...any) -> ...any avoids assuming a particular parameter or return shape.

Change

Add the missing PrimitiveType to FunctionType subtyping case and accept it only when the target has both an exactly variadic any argument pack and an exactly variadic any return pack.

This mirrors the existing treatment of the table primitive, which is accepted as a subtype of the empty table type {} but not more specific table shapes, via a shape check on the supertype rather than error suppression (Subtyping.cpp:2474).

The change is guarded by LuauFunctionPrimitiveIsSubtypeOfVariadicAnyFunction.

Fixes #2657.

Testing

Added seven focused tests covering:

  • function as a subtype of (...any) -> ...any
  • The end to end reproduction from function should be a valid type for annotations of (...any) -> ...any #2657
  • Rejection of function <: () -> ()
  • Rejection of function <: (...any) -> ()
  • Rejection of concrete function signatures
  • Preserving concrete function subtyping to function
  • Preventing other primitive types from satisfying (...any) -> ...any

The two positive tests were verified to be load bearing by temporarily neutralizing only the new subtyping case. The remaining tests guard unchanged behaviour.

@Companion
Companion requested a review from a team as a code owner August 30, 2026 11:01
@Companion
Companion requested a review from andyfriesen August 30, 2026 11:01
@Companion
Companion force-pushed the fix/function-type-as-variadic-callable branch from 97b7920 to 3073dae Compare September 1, 2026 00:52
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.

function should be a valid type for annotations of (...any) -> ...any

1 participant