Skip to content

Unnecessary ambiguity in overload resolution involving tuple wrapping parameter pack #82172

Open
@xwu

Description

@xwu

Description

All credit to Matt Curtis for reducing this issue to the following:

func write<T>(_ value: T) { } // 1
func write<each T>(_ values: (repeat each T)) { } // 2

write(1) // Ambiguous use of 'write'

If (2) were instead written so as not to wrap the parameter pack in a tuple, it would be disfavored by today's compiler. But when wrapped in a tuple as here, the compiler complains of ambiguity. The discrepancy isn't really justified, and (1) should be considered "more specific" than (2).

For more see https://forums.swift.org/t/non-copyable-types-and-function-overload-resolution/80383/4

Reproduction

func write<T>(_ value: T) { } // 1
func write<each T>(_ values: (repeat each T)) { } // 2

write(1) // Ambiguous use of 'write'

Expected behavior

Expect invocation of first overload

Environment

Swift 6.1

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions