Skip to content

Commit f1a5f8c

Browse files
committed
Exit test __capturedValue tweak
1 parent c7cc42b commit f1a5f8c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Sources/Testing/Expectations/Expectation+Macro.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public macro require(
588588
/// macro. Do not use it directly.
589589
@freestanding(expression)
590590
public macro __capturedValue<T>(
591-
_ value: T,
591+
_ value: borrowing T,
592592
_ name: String,
593593
_ expectedType: T.Type
594594
) -> T = #externalMacro(module: "TestingMacros", type: "ExitTestCapturedValueMacro") where T: Sendable & Codable
@@ -611,7 +611,7 @@ public macro __capturedValue<T>(
611611
_ value: borrowing T,
612612
_ name: String,
613613
_ expectedType: T.Type
614-
) -> Never = #externalMacro(module: "TestingMacros", type: "ExitTestBadCapturedValueMacro") where T: ~Copyable & ~Escapable
614+
) -> T = #externalMacro(module: "TestingMacros", type: "ExitTestBadCapturedValueMacro") where T: ~Copyable & ~Escapable
615615

616616
/// Emit a compile-time diagnostic when a value is captured by an exit test but
617617
/// we inferred the wrong type.

Sources/TestingMacros/ExitTestCapturedValueMacro.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public struct ExitTestBadCapturedValueMacro: ExpressionMacro, Sendable {
5050
// Diagnose that the type of 'expr' is invalid.
5151
context.diagnose(.capturedValueMustBeSendableAndCodable(expr, name: nameExpr))
5252

53+
if let typeExpr = arguments[2].expression.as(MemberAccessExprSyntax.self)?.base?.as(TupleExprSyntax.self)?.elements.first?.expression {
54+
return "(\(ExprSyntax.unreachable) as! \(typeExpr.trimmed))"
55+
}
5356
return .unreachable
5457
}
5558
}

0 commit comments

Comments
 (0)