For SwiftUI.List rowContent: How to define a func with a @Binding property wrapper as parameter?

Edit: answer:

// Define it like this:
func itemView(@Binding _ user: User) -> some View { ... }

// Call it like this:
 List($model.users) { $user in
    itemView($_: $user)     // 👈👈 🐞 Compiler error here: Extraneous argument label '$_:' in call
}
// omit parameter label call should work ...
// but as of Xcode Version 13.0 beta 4 (13A5201i), the above do not compile

// this works:
// Define it like this:
func itemView(@Binding user: User) -> some View { ... }

// Call it like this:
 List($model.users) { $user in
    itemView($user: $user)
}

// Or call it this way:
List($model.users, rowContent: itemView($user:))    // 👈👈 💥 this cause preview to crash, sim okay

See SE-0293

Original post:

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

    // 0) instead of the following, which works
    // would like to extract the `rowContent` closure to a separate func
    var bodyOG: some View {
        List($model.users) { $user in
            //
            // 1) **** want to extract the following to a func itemView(...)
            //
            VStack {
                HStack {
                    Text(user.name)
                    Spacer()
                    Toggle("User has been contacted", isOn: $user.isContacted)
                        .labelsHidden()
                }
                Text("Contacted: \(user.isContacted ? "Yes" : "No")")
            }
        }
    }

    // 2) I want this way
    var body: some View {
        // this does not work
        // rowContent signature is <#T##(Binding<Data.Element>) -> RowContent#>
//        List($model.users, rowContent: itemView)    // Compile error: Cannot convert value of type '(User) -> some View' to expected argument type '(Binding<[User]>.Element) -> some View' (aka '(Binding<User>) -> some View')

        // this also doesn't work
        List($model.users) { $user in
            itemView($user)
        }
    }

    // 3) *** what's the correct thing to do here?
    //    what should the function signature be using SE-0293 syntax?
    func itemView(@Binding _ user: User) -> some View {   // Compile error: Property type 'Binding<[User]>.Element' (aka 'Binding<User>') does not match 'wrappedValue' type 'User'
        VStack {
            HStack {
                Text(user.name)
                Spacer()
                Toggle("User has been contacted", isOn: $user.isContacted)
                    .labelsHidden()
            }
            Text("Contacted: \(user.isContacted ? "Yes" : "No")")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        let data = [
            User(name: "Larry"),
            User(name: "Curly"),
            User(name: "Moe")
        ]
        ContentView()
            .environmentObject(Model(data))
    }
}

Have you tried

    func itemView(_ user: Binding<User>) -> some View {

instead?

Doesn't work: same error and $user become undefined.

I'm trying to keep usijng the SE-0293 Extend Property Wrappers to Function and Closure Parameters. That's what the List($model.users) rowContent closure parameter is.

See: my earlier post.

I don't have beta access to mess around with the new toys, but that seems weird. Since user is a Binding and the projectedValue of a Binding (which I think is what $user means) should give you the binding itself, I would expect $user to be a valid reference. Maybe I'm misunderstanding how it is supposed to work. My knowledge of Binding is mostly academic rather than practical.

The rowContent closure parameter is a Binding<User>. The magic happen with SE-0293: if you name the parameter as $user, which is still a Binding<User>, SE-0293 then defines user as $user.wrappedValue.

How to write a func for the rowContent closure? Seems to me this should work:

func itemView(_ user: Binding<User>) -> some View {

why is this compile error:

Property type 'Binding<[User]>.Element' (aka 'Binding<User>') does not match 'wrappedValue' type 'User'

AFAICT, you want to pass in Binding<User>, which is an API wrapper, and use a wrapped User on callee side. In that case, the function signature should look like this:

func itemView(@Binding _ user: User) -> some View {
  // `_user` is `Binding<User>`
  // `$user` is `Binding<User>`
  // `user` is `User`
}

and the call site could look like this:

// `x` is `Binding<User>`
itemView($_: x) 

Technically, you're passing the projectedValue when using this syntax. It is a little confusing in case of Binding because its projected value has the same type as the storage. Let's say we have a wrapper:

struct Storage {
  var projectedValue: Projected
  var wrappedValue: Wrapped

  init(projectedValue: Projected) { ... }
  init(wrappedValue: Wrapped) { ... }
}

and a function:

function a(@Storage x: ...) {
  // `_x` is `Storage`
  // `$x` is `Projected`
  // `x` is `Wrapped`
}

Then you can to pass the storage's projected value or wrapped value. In both cases, the language uses the appropriate initializer to create a new Storage:

a(x: y) // Uses `init(wrappedValue: y)`
a($x: z) // Uses `init(projectedValue: z)`

If no such initializer is declared inside the type declaration, then of course, you can't use the respective caller's syntax.

2 Likes

:scream::scream::raised_hands:

This doesn't compile:

itemView($_: $user)     // Extraneous argument label '$_:' in call

...

func itemView(@Binding _ user: User) -> some View { ... }

Should it compile? Is this a compiler bug?

This work:

itemView($user: $user)
// or
itemView($user: $0)    // use shorthand closure parameter

...

func itemView(@Binding user: User) -> some View { ... }

How does this work? Since func with property wrapper parameter can be called either ways:

From SE-0293 Call-site semantics:

log(value: 10)
log($value: history)

Does the compiler generate two different function signatures?

I was hoping to do this (So that I can avoid adding one extra closure and call itemView directly):

List($model.users, rowContent: itemView)
// Compile error: Cannot convert value of type '(User) -> some View' to expected argument type '(Binding<[User]>.Element) -> some View' (aka '(Binding<User>) -> some View')

but this does not compile. I wish there is something like this:

List($model.users, rowContent: itemView[use the $ version of this])

Edit:

and there is such thing:

List($model.users, rowContent: itemView($user:))

So there are indeed two signatures.

see: Unapplied function references

If a wrapped parameter omits an argument label, the function can be referenced to take in the projected-value type using $_ :slight_smile:

this not work is definitely a compiler bug

It definitely should be $_ for unlabeled parameters. Looks like a bug. Maybe you can file a report.

Technically, it compiles down to one function:

func _itemView(_ user: Binding<User>)

and the magic overload happens at call site:

itemView($user: x)
// turns into
_itemView(user: .init(projectedValue: x))

itemView(user: y)
// turns into
_itemView(user: .init(wrappedValue: x))

@hborla ? Thanks!

Cannot submit bug report to bugs.swift.org:

We can't create this issue for you right now, it could be due to unsupported content you've entered into one or more of the issue fields. If this situation persists, contact your administrator as they'll be able to access more specific information in the log file.

Odd compiler error:

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()
    }
}

The error is at the wrong place and misleading. This maybe due to API-level property wrappers:

Property wrappers that declare an init(projectedValue:) initializer are inferred to be API-level wrappers. These wrappers become part of the function signature, and the property wrapper is initialized at the call-site of the function.

=======

Bug #1: itemView($_: $user) do not compile:

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)     // 👈👈 🐞 Compiler error here: Extraneous argument label '$_:' in call
        }
    }

    func itemView(@Binding _ user: User) -> some View {
        EmptyView()
    }
}

Bug #2: Xcode SwiftUI preview crash, run in sim is fine:

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, rowContent: itemView($user:))    // 👈👈 💥 this cause preview to crash
        // this works:
        List($model.users) { $user in
            itemView($user: $user)
        }
    }

    func itemView(@Binding user: User) -> some View {
        EmptyView()
    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        let data = [
            User(name: "Larry"),
            User(name: "Curly"),
            User(name: "Moe")
        ]
        ContentView()
            .environmentObject(Model(data))
    }
}

This one maybe problem with SwiftUI preview and how it interact with SE-0293.

Crash log

CompileDylibError: Failed to build ContentView.swift

Check the issue navigator for any compilation errors.

Please submit a bug report (Swift.org - Contributing) and include the project and the crash backtrace.
Stack dump:
0. Program arguments: /Users/mateo/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.swift -serialize-diagnostics-path /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.dia -target x86_64-apple-ios14.0-simulator -enable-objc-interop -sdk /Users/mateo/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk -I /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Products/Debug-iphonesimulator -F /Users/mateo/Applications/Xcode-beta.app/Contents/SharedFrameworks-iphonesimulator -F /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Products/Debug-iphonesimulator -enable-testing -module-cache-path /Users/mateo/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -emit-localized-strings -emit-localized-strings-path /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64 -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -new-driver-path /Users/mateo/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -serialize-debugging-options -disable-modules-validate-system-headers -Xcc -working-directory -Xcc /Users/mateo/Devel/BugsBugs/PreviewCrashForFuncWPropWrapperParam -resource-dir /Users/mateo/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/PreviewCrashForFuncWPropWrapperParam-generated-files.hmap -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/PreviewCrashForFuncWPropWrapperParam-own-target-headers.hmap -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/PreviewCrashForFuncWPropWrapperParam-all-target-headers.hmap -Xcc -iquote -Xcc /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/PreviewCrashForFuncWPropWrapperParam-project-headers.hmap -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Products/Debug-iphonesimulator/include -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/DerivedSources-normal/x86_64 -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/DerivedSources/x86_64 -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/DerivedSources -Xcc -DDEBUG=1 -module-name PreviewCrashForFuncWPropWrapperParam_PreviewReplacement_ContentView_2 -target-sdk-version 15.0.0 -o /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.o

  1. Apple Swift version 5.5 (swiftlang-1300.0.27.6 clang-1300.0.27.2)
  2. While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.swift")
  3. While silgen emitFunction SIL function "@$s36PreviewCrashForFuncWPropWrapperParam11ContentViewV0abcdefg1_a12Replacement_hI2_2E15__preview__body33_7817697A203B92A1C9DFE2D362513A75LLQrvg".
    for getter for __preview__body (at /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.swift:28:49)
  4. While silgen closureexpr SIL function "@$s36PreviewCrashForFuncWPropWrapperParam11ContentViewV0abcdefg1_a12Replacement_hI2_2E15__preview__body33_7817697A203B92A1C9DFE2D362513A75LLQrvgAC04itemI04userQr7SwiftUI7BindingVyAA4UserVG_tFQOy_Qo_ANcACcfu_".
    for expression at [/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.swift:28:40 - line:28:55] RangeText="itemView($user:"
  5. While silgen closureexpr SIL function "@$s36PreviewCrashForFuncWPropWrapperParam11ContentViewV0abcdefg1_a12Replacement_hI2_2E15__preview__body33_7817697A203B92A1C9DFE2D362513A75LLQrvgAC04itemI04userQr7SwiftUI7BindingVyAA4UserVG_tFQOy_Qo_ANcACcfu_AoNcfu0_".
    for expression at [/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.swift:28:40 - line:28:55] RangeText="itemView($user:"
    Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
    0 swift-frontend 0x0000000112542187 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
    1 swift-frontend 0x0000000112541118 llvm::sys::RunSignalHandlers() + 248
    2 swift-frontend 0x0000000112542796 SignalHandler(int) + 278
    3 libsystem_platform.dylib 0x00007ff818c8e06d _sigtramp + 29
    4 libsystem_platform.dylib 0xf6abc000c0001003 _sigtramp + 17774370760257122227
    5 swift-frontend 0x000000010ddd0a37 swift::SILInstructionVisitor<LazyConformanceEmitter, void>::visit(swift::SILInstruction*) + 999
    6 swift-frontend 0x000000010dd2c66b swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 2043
    7 swift-frontend 0x000000010ddbdec0 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 240
    8 swift-frontend 0x000000010dda99af swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 143
    9 swift-frontend 0x000000010de21f92 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 450
    10 swift-frontend 0x000000010ddca113 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 1011
    11 swift-frontend 0x000000010dd2c60e swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 1950
    12 swift-frontend 0x000000010dd577ff (anonymous namespace)::SILGenApply::visitAbstractClosureExpr(swift::AbstractClosureExpr*) + 607
    13 swift-frontend 0x000000010dd3f45b swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 251
    14 swift-frontend 0x000000010dda997f swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 95
    15 swift-frontend 0x000000010dd9d808 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
    16 swift-frontend 0x000000010dd87e69 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 393
    17 swift-frontend 0x000000010dd513e6 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3446
    18 swift-frontend 0x000000010dd3cf29 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 169
    19 swift-frontend 0x000000010dd594d3 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapperswift::SILFunctionType, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImplswift::Lowering::ManagedValue&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::Lowering::CalleeTypeInfo::ForeignInfo const&) && + 675
    20 swift-frontend 0x000000010dd58f7c (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapperswift::SILFunctionType, swift::Lowering::CalleeTypeInfo::ForeignInfo const&, llvm::SmallVectorImplswift::Lowering::ManagedValue&, llvm::Optionalswift::SILLocation&) + 1276
    21 swift-frontend 0x000000010dd42029 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2537
    22 swift-frontend 0x000000010dd3fde6 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2694
    23 swift-frontend 0x000000010dda997f swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 95
    24 swift-frontend 0x000000010dd9aac6 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optionalswift::SILLocation) + 118
    25 swift-frontend 0x000000010dd8d57a swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 2250
    26 swift-frontend 0x000000010dd3238d swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 125
    27 swift-frontend 0x000000010de19c2c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 460
    28 swift-frontend 0x000000010ddc8d68 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 776
    29 swift-frontend 0x000000010dd2e2c0 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 9296
    30 swift-frontend 0x000000010dd306f8 emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef, bool) + 376
    31 swift-frontend 0x000000010dd2be58 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 216
    32 swift-frontend 0x000000010de30785 SILGenExtension::visitFuncDecl(swift::FuncDecl*) + 277
    33 swift-frontend 0x000000010e8bdd1a swift::AbstractStorageDecl::visitEmittedAccessors(llvm::function_ref<void (swift::AccessorDecl*)>) const + 90
    34 swift-frontend 0x000000010de30658 SILGenExtension::visitVarDecl(swift::VarDecl*) + 360
    35 swift-frontend 0x000000010de2c21b SILGenExtension::emitExtension(swift::ExtensionDecl*) + 59
    36 swift-frontend 0x000000010dd36092 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1938
    37 swift-frontend 0x000000010dd3344c swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 4172
    38 swift-frontend 0x000000010de19655 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_deleteswift::SILModule > (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 197
    39 swift-frontend 0x000000010dd383ec llvm::Expectedswift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncachedswift::ASTLoweringRequest(swift::ASTLoweringRequest const&) + 652
    40 swift-frontend 0x000000010d679868 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 13304
    41 swift-frontend 0x000000010d5bb718 main + 1032
    42 dyld 0x000000011968f4d5 start + 421

==================================

| BuildInvocationError
|
| /Users/mateo/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -F /Users/mateo/Applications/Xcode-beta.app/Contents/SharedFrameworks-iphonesimulator -enforce-exclusivity=checked -DDEBUG -sdk /Users/mateo/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk -target x86_64-apple-ios14.0-simulator -module-cache-path /Users/mateo/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -Xfrontend -serialize-debugging-options -enable-testing -swift-version 5 -I /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Products/Debug-iphonesimulator -F /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Products/Debug-iphonesimulator -emit-localized-strings -emit-localized-strings-path /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64 -c -j4 -serialize-diagnostics -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/PreviewCrashForFuncWPropWrapperParam-generated-files.hmap -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/PreviewCrashForFuncWPropWrapperParam-own-target-headers.hmap -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/PreviewCrashForFuncWPropWrapperParam-all-target-headers.hmap -Xcc -iquote -Xcc /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/PreviewCrashForFuncWPropWrapperParam-project-headers.hmap -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Products/Debug-iphonesimulator/include -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/DerivedSources-normal/x86_64 -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/DerivedSources/x86_64 -Xcc -I/Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/DerivedSources -Xcc -DDEBUG=1 -working-directory /Users/mateo/Devel/BugsBugs/PreviewCrashForFuncWPropWrapperParam /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.swift -o /Users/mateo/Library/Developer/Xcode/DerivedData/PreviewCrashForFuncWPropWrapperParam-dwnrppkkgaqzyibjpemqiooqvwqg/Build/Intermediates.noindex/Previews/PreviewCrashForFuncWPropWrapperParam/Intermediates.noindex/PreviewCrashForFuncWPropWrapperParam.build/Debug-iphonesimulator/PreviewCrashForFuncWPropWrapperParam.build/Objects-normal/x86_64/ContentView.2.preview-thunk.o -module-name PreviewCrashForFuncWPropWrapperParam_PreviewReplacement_ContentView_2 -Onone -Xfrontend -disable-modules-validate-system-headers

https://bugs.swift.org/browse/SR-15030
https://bugs.swift.org/browse/SR-15031
https://bugs.swift.org/browse/SR-15032

1 Like

You probably need to send the bug report to Apple not bugs.swift.org since it relates to SwiftUI.

The sample code use SwiftUI but the bugs are are not SwiftUI bugs.

The first two are compiler bugs so they should go to bugs.swift.org.

The last one the crash log message link to Swift.org - Contributing and the page point to bugs.swift.org.

Terms of Service

Privacy Policy

Cookie Policy