Skip to content

[SR-16076] Compiler crashes in release mode when using compactMap with a key path to an @objc optional property #58337

@davedelong

Description

@davedelong
Previous ID SR-16076
Radar None
Original Reporter @davedelong
Type Bug
Environment

Xcode 13.3 and Xcode 13.2.1

Additional Detail from JIRA
Votes 0
Component/s swift
Labels Bug
Assignee @AnthonyLatsis
Priority Medium

md5: 2b2d253ea8e84f4670e030c4b62dd6c5

Issue Description:

Given this code:

@objc protocol OptionalVar {
    @objc optional var name: String { get }
}

extension NSObject: OptionalVar { }

let objects = [
    NSObject(),
    NSObject(),
    NSObject()
] as Array<OptionalVar>

let names = objects.compactMap(\.name)
print("Names: \(names)")

This will build and run fine in debug mode (-Onone), but the compiler crashes when in building in release mode (-O).

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwarekey pathsFeature: key paths (both native and Objective-C)optimized onlyFlag: An issue whose reproduction requires optimized compilationoptional protocol requirementsFeature → protocol: optional protocol requirementsswift 5.6

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions