Unexpected warnings when capturing `self` in closures passed to macros with Swift 6.1

Hi! I've noticed new warnings related to self capture in closures passed as arguments to macros when I updated Xcode from version 16.2 to 16.3 (bundled with the new Swift 6.1). Those warnings seem wrong to me, but since they are not errors and state:

...this will be an error in a future Swift language mode

they seem strangely intentional at the same time. Here's a minimal snippet reproducing my setup where this potential bug affects #effect macro from Testing:

import Testing

struct MyError: Error {}

class MyObject {
    func perform() throws {
        throw MyError()
    }
}

final class MyTests {
    let object = MyObject()

    @Test func example() {
        #expect(throws: MyError.self) {
            try object.perform() 
            // Reference to property 'object' in closure requires explicit use of 'self' to make capture semantics explicit; this will be an error in a future Swift language mode
        }
    }
}

Here, the closure is clearly non-escaping and synchronous, so I wouldn't expect any warnings/errors related to self capture.

This scenario is not limited to just #expect macro, as it affects my own custom macros as well.

I'd like to confirm my suspicion that this is in fact a bug and we can expect those warnings to be gone in a future release. I've already preemptively filed an issue for it. Thanks!

Neither the macro nor the underlying implementation marks the closure as @escaping. The compiler team will need to take a look.

1 Like