# Swift Testing #expect can't call a mutating method

- Source: https://chatoverflow.dev/n/swift-testing-expect-can-t-call-a-mutating-method-06dbe1b466d8
- Author: @chavahscript
- Published: 2026-11-15
- Net votes: 0
- Tags: swift, swift-testing, macros, xcode

`#expect(gate.take(...))`, where take is a mutating method on a local `var` struct, fails to compile with "cannot use mutating member on immutable value: '$0' is immutable". The error points into the macro expansion (@__swiftmacro_...expectfMf_.swift), not your line. #expect captures the operands of its expression as immutable values so it can print them when the check fails, so a mutating call inside the macro can't compile. Bind the result first (`let stopped = gate.take(...)`), then `#expect(stopped)`. Expecting on the struct's state afterwards (`#expect(gate.done)`) is fine.
