You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't capture arguments to #expect(exitsWith:) during macro expansion. (#912)
Other than the body closure, the arguments to `#expect(exitsWith:)` are
not guaranteed to be literals or otherwise context-free, but we capture
them during macro expansion. This can result in obscure errors if the
developer writes an exit test with an argument that is computed:
```swift
let foo = ...
await #expect(exitsWith: self.exitCondition(for: foo)) {
// 🛑 error: closure captures 'foo' before it is declared
// 🛑 error: enum declaration cannot close over value 'self' defined in outer scope
// (and other possible errors)
...
}
```
This PR removes the macro's compile-time dependency on its
`exitCondition` and `sourceLocation` arguments and introduces an `ID`
type to identify exit tests (instead of using their source locations as
unique IDs.) The `ID` type is meant to be a UUID, but for the moment
I've just strung together two 64-bit integers instead to avoid a
dependency on Foundation or platform API.
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
Copy file name to clipboardExpand all lines: Documentation/ABI/TestContent.md
+11-3Lines changed: 11 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -118,9 +118,17 @@ to by `hint` depend on the kind of record:
118
118
- For exit test declarations (kind `0x65786974`), the accessor produces a
119
119
structure describing the exit test (of type `__ExitTest`.)
120
120
121
-
Test content records of this kind accept a `hint` of type `SourceLocation`.
122
-
They only produce a result if they represent an exit test declared at the same
123
-
source location (or if the hint is `nil`.)
121
+
Test content records of this kind accept a `hint` of type `__ExitTest.ID`.
122
+
They only produce a result if they represent an exit test declared with the
123
+
same ID (or if `hint` is `nil`.)
124
+
125
+
> [!WARNING]
126
+
> Calling code should use [`withUnsafeTemporaryAllocation(of:capacity:_:)`](https://developer.apple.com/documentation/swift/withunsafetemporaryallocation(of:capacity:_:))
127
+
> and [`withUnsafePointer(to:_:)`](https://developer.apple.com/documentation/swift/withunsafepointer(to:_:)-35wrn),
128
+
> respectively, to ensure the pointers passed to `accessor` are large enough and
129
+
> are well-aligned. If they are not large enough to contain values of the
130
+
> appropriate types (per above), or if `hint` points to uninitialized or
131
+
> incorrectly-typed memory, the result is undefined.
0 commit comments