luau icon indicating copy to clipboard operation
luau copied to clipboard

[new solver] Optional argument in overloaded function requires explicit nil for type checking in Luau

Open jiwonz opened this issue 2 months ago • 0 comments

Bug Description:

When using function overloading in Luau, optional arguments do not work as expected. For example, with the following type:

export type ReliabilityType = "reliable" | "unreliable"
export type Net = {
  defined: (<T>(direction: "server->client", value: T, reliability_type: ReliabilityType?) -> ServerEvent<T>)
        & (<T>(direction: "client->server", value: T, reliability_type: ReliabilityType?) -> ClientEvent<T>),
}

If you call Net.defined("server->client", value) without specifying the optional reliability_type argument, the type checker fails with None of the overloads for function that accept 2 arguments are compatible.. You must explicitly pass nil as the third argument (Net.defined("server->client", value, nil)) for type checking to succeed. This is unexpected behavior; optional arguments should be truly optional and should not require explicit nil.

Expected Behavior: Overloaded functions with optional arguments should allow calls without passing explicit nil for those arguments.

Actual Behavior: Type checking fails unless nil is explicitly passed as an optional argument in overloaded function signatures.

jiwonz avatar Oct 28 '25 05:10 jiwonz