Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AnthonyLatsis opened this issue May 26, 2025 · 0 comments
Open

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

AnthonyLatsis opened this issue May 26, 2025 · 0 comments
Labels
compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation expressions Feature: expressions overload resolution Area → compiler → type checker: Overload resolution (ranking) swift 6.2 type checker Area → compiler: Semantic analysis

Comments

@AnthonyLatsis
Copy link
Collaborator

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

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis overload resolution Area → compiler → type checker: Overload resolution (ranking) swift 6.2 expressions Feature: expressions labels May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler itself diagnostics QoI Bug: Diagnostics Quality of Implementation expressions Feature: expressions overload resolution Area → compiler → type checker: Overload resolution (ranking) swift 6.2 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant