Skip to content

[SR-15121] Segfault when KeyPath expression as function used for functions on classes #57447

Closed
@DeFrenZ

Description

@DeFrenZ
Previous ID SR-15121
Radar None
Original Reporter @DeFrenZ
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 1b2bc84d40d51034214b603bf5e65311

Issue Description:

final class WorkItem {
    let work: () -> Void    
    init(work: @escaping () -> Void) {
        self.work = work
    }
}


var items: [WorkItem] = [
    .init(work: { print("foo") }),
]


items.forEach(\.work) // SEGFAULT
items.forEach({ $0.work() }) // WORKS

This doesn't crash if `WorkItem` is a `struct` instead, but doesn't print either (without the correct call).

The last stack item before the crash is "libswiftCore.dylib`swift::metadataimpl::ValueWitnesses<(anonymous namespace)::ThickFunctionBox>::initializeWithTake"

The issue is that it probably shouldn't compile at all with the expression, since the type mismatches

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions