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-15030] Odd compiler error message at the wrong place (maybe SE-0293 related) #57357

Open
mattyoung opened this issue Aug 5, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@mattyoung
Copy link

Previous ID SR-15030
Radar None
Original Reporter @mattyoung
Type Bug
Environment

Xcode Version 13.0 beta 4 (13A5201i)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 4e028df6a9b1906d7436b447fa621fed

Issue Description:

Create a Xcode SwiftUI iOS app, paste this into the ContentView.swift file:

import SwiftUI

struct User: Identifiable {
    let id = UUID()
    var name: String
    var isContacted = false
}

final class Model: ObservableObject {
    @Published var users: [User]

    init(_ users: [User]) {
        self.users = users
    }
}

struct ContentView: View {
    @EnvironmentObject private var model: Model

    var body: some View {
        List($model.users) { $user in
            itemView(user: $user)     // <=== !!! very odd, no compile error here, but error over at the func definition!
            itemView($user: $user)    // change the previous line to this the error below goes away
        }

    }

    // there is nothing wrong with this, but if the call site is wrong, compiler error here
    // this erroneous error message makes to look like the func definition here is wrong, but it's fine 
    func itemView(@Binding user: User) -> some View { // <=== !!! why compile error here? => Property type 'Binding<User>' does not match 'wrappedValue' type 'User'
                                                      // fix the call site, this error goes away
        EmptyView()
    }
}

See: https://forums.swift.org/t/for-swiftui-list-rowcontent-how-to-define-a-func-with-a-binding-property-wrapper-as-parameter/50782/9

@hborla
Copy link
Member

hborla commented Sep 2, 2021

I have a PR to fix this here: #39146

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants