Skip to content
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

[SR-11473] Misleading error from wrong type #53873

Closed
swift-ci opened this issue Sep 14, 2019 · 5 comments
Closed

[SR-11473] Misleading error from wrong type #53873

swift-ci opened this issue Sep 14, 2019 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11473
Radar rdar://problem/55486679
Original Reporter stevex (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 11 GM Seed

macOS 10.14.6

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee stevex (JIRA)
Priority Medium

md5: bbed4f32829eeb9f8c2cfb275741f539

Issue Description:

In a nutshell:

struct LockState {
    let correctCode = "7492"
    var currentCode = ""
}

struct ClownPadView: View {
    @State var state = LockState()


    var body: some View {
        VStack(alignment: .leading) {
            Text("Code is \(state.currentCode)")
            ForEach(0...9, id: \.self) { v in
                Button("\(v)") {
                    // Error here - currentCode is a string, 
                    // v is an Int, can't append an int
                    self.state.currentCode.append(v)
                }
            }
        }
    }
}

The error reported is:

Static member 'leading' cannot be used on instance of type 'HorizontalAlignment'

On the VStack line.

Expected output would be "Cannot invoke 'append' with an argument list of type '(Int)'" on the append() line.

Simple Xcode project attached.

@belkadan
Copy link
Contributor

@xedin, do your recent changes fix this?

@xedin
Copy link
Member

xedin commented Sep 18, 2019

Not this one unfortunately, looks like the problem here is related to generic requirements placed on `append` overload which could potentially match.

@xedin
Copy link
Member

xedin commented Sep 18, 2019

@swift-ci create

@xedin
Copy link
Member

xedin commented May 8, 2020

Looks like on master we produce a much better error for this situation:

error: instance method 'append(contentsOf:)' requires that 'Int' conform to 'Sequence'
                    self.state.currentCode.append(v)
                               ^

stevex (JIRA User) Could use please use the latest nightly build of master to verify and close?

@xedin
Copy link
Member

xedin commented Apr 2, 2021

Even better diagnostic on main:

error: no exact matches in call to instance method 'append'
                    self.state.currentCode.append(v)
Swift.String:6:26: note: candidate expects value of type 'String' for parameter #​1
    public mutating func append(_ other: String)
                         ^
Swift.String:7:26: note: candidate expects value of type 'Character' for parameter #​1
    public mutating func append(_ c: Character)
                         ^

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

3 participants