Skip to content

Bad diagnostic for .init + argument label mismatch + overloads #81778

Open
@AnthonyLatsis

Description

@AnthonyLatsis

Description

No response

Reproduction

struct S {
  init(i: Int) {}
}

var arrB: [S] = []
arrB.append(.init(x: ""))
test.swift:98:6: error: no exact matches in call to instance method 'append' [no_overloads_match_exactly_in_call]
arrB.append(.init(x: ""))
     ^
Swift.Array.append:2:33: note: incorrect labels for candidate (have: '(_:)', expected: '(contentsOf:)') [candidate_expected_different_labels]
@inlinable public mutating func append<S>(contentsOf newElements: __owned S) where Element == S.Element, S : Sequence}
                                ^
Swift.RangeReplaceableCollection.append:2:33: note: incorrect labels for candidate (have: '(_:)', expected: '(contentsOf:)') [candidate_expected_different_labels]
@inlinable public mutating func append<S>(contentsOf newElements: __owned S) where S : Sequence, Self.Element == S.Element}
                                ^
test.swift:98:14: error: 'Sequence' cannot be constructed because it has no accessible initializers [no_accessible_initializers]
arrB.append(.init(x: ""))

Expected behavior

This combination of issues is causing us to prefer the more abstract append(contentsOf:) solution. I would expect it to carry more reasons to be disfavored due to the additional argument label mismatch and absence of a viable initializer.

Environment

Swift version 6.2-dev (LLVM c23e68dd0fa9228, Swift 278248e)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsoverload resolutionArea → compiler → type checker: Overload resolution (ranking)swift 6.2type checkerArea → compiler: Semantic analysis

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions