Fix function not being a valid type for (...any) -> ...any annotations - #2725
Open
Companion wants to merge 1 commit into
Open
Fix function not being a valid type for (...any) -> ...any annotations#2725Companion wants to merge 1 commit into
Companion wants to merge 1 commit into
Conversation
Companion
force-pushed
the
fix/function-type-as-variadic-callable
branch
from
September 1, 2026 00:52
97b7920 to
3073dae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
functionprimitive represents the set of all function types, but it is not currently accepted as a subtype of the(...any) -> ...anyannotation:This causes valid annotations to be rejected:
This is distinct from #2656, which was closed as by design. That issue attempted to use
functionas a subtype of specific function signatures, which is unsafe and remains rejected:function <: () -> ()function <: (...any) -> ()function <: (...any) -> ...any(number) -> string <: functionOf these, only
(...any) -> ...anyavoids assuming a particular parameter or return shape.Change
Add the missing
PrimitiveTypetoFunctionTypesubtyping case and accept it only when the target has both an exactly variadicanyargument pack and an exactly variadicanyreturn pack.This mirrors the existing treatment of the
tableprimitive, 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:
functionas a subtype of(...any) -> ...anyfunctionshould be a valid type for annotations of(...any) -> ...any#2657function <: () -> ()function <: (...any) -> ()function(...any) -> ...anyThe two positive tests were verified to be load bearing by temporarily neutralizing only the new subtyping case. The remaining tests guard unchanged behaviour.