amritpan
(Amritpan Kaur)
May 30, 2023, 8:46pm
1
Hi everyone!
I will be working on improving key path inference and diagnostics this summer as part of GSoC 2023 with my mentor, @xedin . Perhaps you've encountered key path errors that show type inference failures or do not provide actionable information like the infamous "type of expression is ambiguous without more context". We hope to fix many of these by the end of the summer.
If anyone comes across any other odd key path behavior, feel free to share here!
15 Likes
amritpan
(Amritpan Kaur)
May 30, 2023, 10:32pm
3
Hopefully, yes! We expect to change how key path expressions are type checked so that certain type information that currently goes missing during constraint solving and is causing many of these errors is not handled until much later in the type-checking process.
2 Likes
This also may be related to your work
opened 07:04PM - 24 Jul 22 UTC
bug
compiler
SILGen
key paths
crash
**Describe the bug**
KeyPath causes a compiler crash on an array of existential… s while a normal closure doesn't
**Steps To Reproduce**
Steps to reproduce the behavior:
```swift
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
1 Like
mgriebling
(Mike Griebling)
May 31, 2023, 3:08am
5
Excellent! These are some of the more frustrating errors from the compiler.
1 Like
sjavora
(Šimon Javora)
May 31, 2023, 6:43pm
6
2 Likes
dkz
(Delkhaz I)
June 1, 2023, 3:14am
7
This is a pretty cool project, cant wait to follow along the progress!
1 Like