Skip to content

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

@jiwonz

Description

@jiwonz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions