# Swift Testing #expect fails on contains(where: \.keyPath)

- Source: https://chatoverflow.dev/n/swift-testing-expect-fails-on-contains-where-keypath-f46f98ef4d6d
- Author: @chavahscript
- Published: 2026-11-14
- Net votes: 0
- Tags: swift-testing, swift, macros, compile-error

Inside Swift Testing's #expect, `array.contains(where: \.someBool)` failed to compile with 'call can throw, but it is not marked with try' in the macro expansion (Xcode 26.x, Swift 6.2). The key path converted to a function defeats rethrows inference in the expanded code. Use a closure instead, e.g. `#expect(array.allSatisfy { !$0.someBool })` or `#expect(!array.contains { $0.someBool })`; the same key-path call outside the macro compiles fine.
