Closed as duplicate of#543
Closed as duplicate of#543
Description
Description
A property access expectation (#expect(someSpan.isEmpty)
) fails to build because it requires that someSpan
is Escapable
, while other types of expectations like binary operator expectations (#expect(someSpan.count == 0)
) do not have the same requirement.
Reproduction
@Test func spanEmpty() {
var source = Data()
var span = source.mutableSpan
#expect(span.isEmpty) // fails to compile
#expect(span.count == 0) // Compiles successfully
}
Produces:
macro expansion #expect:1:9: error: global function '__checkPropertyAccess(_:getting:expression:comments:isRequired:sourceLocation:)' requires that 'MutableSpan<UInt8>' conform to 'Escapable'
`- /Volumes/Development/Repos/Public/swift-foundation/Tests/FoundationEssentialsTests/DataTests.swift:1716:30: note: expanded code originates here
1714 | var source = Data()
1715 | var span = source.mutableSpan
1716 | #expect(span.isEmpty) // fails to compile
| `- note: in expansion of macro 'expect' here
+--- macro expansion #expect --------------------------------------
|1 | Testing.__checkPropertyAccess(span.self,getting: { $0.isEmpty },expression: .__fromPropertyAccess(.__fromSyntaxNode("span"),.__fromSyntaxNode("isEmpty")),comments: [],isRequired: false,sourceLocation: Testing.SourceLocation.__here()).__expected()
| | `- error: global function '__checkPropertyAccess(_:getting:expression:comments:isRequired:sourceLocation:)' requires that 'MutableSpan<UInt8>' conform to 'Escapable'
+------------------------------------------------------------------
1717 | #expect(span.count == 0) // Compiles successfully
1718 | }
Testing.__checkPropertyAccess:1:13: note: 'where T: Escapable' is implicit here
1 | public func __checkPropertyAccess<T>(_ lhs: T, getting memberAccess: (T) -> Bool, expression: __Expression, comments: @autoclosure () -> [Comment], isRequired: Bool, sourceLocation: SourceLocation) -> Result<Void, any Error>
| `- note: 'where T: Escapable' is implicit here
Expected behavior
I would expect that these two would behave consistently as there is no client-visible difference in these types of expectations (ideally it'd work for both so it's easy to write tests with non-escapable types like span)
Environment
↳ Testing Library Version: 6.3-dev (d5b5c5967072052)
Swift version 6.2-dev (LLVM 7f9c8ab4840f392, Swift 7387f85ba276f02)
Target: aarch64-unknown-linux-gnu
Build config: +assertions
Linux nightly-jammy 6.1.68 #1 SMP Fri Nov 22 18:05:17 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux
Additional information
No response