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

KeyPath causes a compiler crash on an existential root #60214

Open
StevenSorial opened this issue Jul 24, 2022 · 3 comments
Open

KeyPath causes a compiler crash on an existential root #60214

StevenSorial opened this issue Jul 24, 2022 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software key paths Feature: key paths (both native and Objective-C) SILGen Area → compiler: The SIL generation stage

Comments

@StevenSorial
Copy link

StevenSorial commented Jul 24, 2022

Describe the bug
KeyPath causes a compiler crash on an array of existentials while a normal closure doesn't

Steps To Reproduce
Steps to reproduce the behavior:

import Foundation

protocol Brand {
  var name: String { get }
}

protocol Car {
  associatedtype BrandType: Brand
  var brand: BrandType { get }
}

func test() {
  let cars: [any Car] = []
  
  let brandsByClosure: [any Brand] = cars.map { $0.brand } // Works
  let brandsByKey: [any Brand] = cars.map(\.brand) // Compiler failure

  let sortedByClosure: [any Car] = cars.sorted { $0.brand.name < $1.brand.name } // Works
  let sortedByKey: [any Car] = cars.sorted(using: KeyPathComparator(\.brand.name)) // Compiler failure
}

Expected behavior
Both forms of map and sorted should work

Environment (please fill out the following information)

  • OS: macOS 12.5
  • Xcode Version/Tag/Branch: Xcode 14.0 beta 3
@StevenSorial StevenSorial added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Jul 24, 2022
@StevenSorial
Copy link
Author

Still crashes in Xcode 14.0 beta 4
Feedback filed: FB10900087

@theblixguy
Copy link
Collaborator

Smaller reproducer:

protocol P {
  associatedtype Assoc
  var value: Assoc { get }
}

func test() {
  let ps: [any P] = []
  _ = ps.map(\.value) // crash
}

@AnthonyLatsis AnthonyLatsis added key paths Feature: key paths (both native and Objective-C) SILGen Area → compiler: The SIL generation stage labels Jul 31, 2022
@AnthonyLatsis
Copy link
Collaborator

Possibly a duplicate of #58289.

@AnthonyLatsis AnthonyLatsis added crash Bug: A crash, i.e., an abnormal termination of software compiler The Swift compiler in itself labels Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software key paths Feature: key paths (both native and Objective-C) SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

4 participants