diff --git a/Sources/Testing/ExitTests/ExitTest.swift b/Sources/Testing/ExitTests/ExitTest.swift index aa7bf39ab..57e38e3ec 100644 --- a/Sources/Testing/ExitTests/ExitTest.swift +++ b/Sources/Testing/ExitTests/ExitTest.swift @@ -399,7 +399,7 @@ extension ExitTest { asTypeAt typeAddress: UnsafeRawPointer, withHintAt hintAddress: UnsafeRawPointer? = nil ) -> CBool { - fatalError("Unimplemented") + swt_unreachable() } } diff --git a/Sources/TestingMacros/ConditionMacro.swift b/Sources/TestingMacros/ConditionMacro.swift index 9d0c4f15f..c176c96b5 100644 --- a/Sources/TestingMacros/ConditionMacro.swift +++ b/Sources/TestingMacros/ConditionMacro.swift @@ -454,9 +454,9 @@ extension ExitTestConditionMacro { // early if found. guard _diagnoseIssues(with: macro, body: bodyArgumentExpr, in: context) else { if Self.isThrowing { - return #"{ () async throws -> Testing.ExitTest.Result in Swift.fatalError("Unreachable") }()"# + return #"{ () async throws -> Testing.ExitTest.Result in \#(ExprSyntax.unreachable) }()"# } else { - return #"{ () async -> Testing.ExitTest.Result in Swift.fatalError("Unreachable") }()"# + return #"{ () async -> Testing.ExitTest.Result in \#(ExprSyntax.unreachable) }()"# } } diff --git a/Sources/TestingMacros/ExitTestCapturedValueMacro.swift b/Sources/TestingMacros/ExitTestCapturedValueMacro.swift index 4bba47c79..bd346bb3b 100644 --- a/Sources/TestingMacros/ExitTestCapturedValueMacro.swift +++ b/Sources/TestingMacros/ExitTestCapturedValueMacro.swift @@ -50,7 +50,7 @@ public struct ExitTestBadCapturedValueMacro: ExpressionMacro, Sendable { // Diagnose that the type of 'expr' is invalid. context.diagnose(.capturedValueMustBeSendableAndCodable(expr, name: nameExpr)) - return #"Swift.fatalError("Unsupported")"# + return .unreachable } } diff --git a/Sources/TestingMacros/Support/Additions/FunctionDeclSyntaxAdditions.swift b/Sources/TestingMacros/Support/Additions/FunctionDeclSyntaxAdditions.swift index 9b9378283..090cb2375 100644 --- a/Sources/TestingMacros/Support/Additions/FunctionDeclSyntaxAdditions.swift +++ b/Sources/TestingMacros/Support/Additions/FunctionDeclSyntaxAdditions.swift @@ -178,3 +178,15 @@ extension FunctionParameterSyntax { return baseType.trimmedDescription } } + +// MARK: - + +extension ExprSyntax { + /// An expression representing an unreachable code path. + /// + /// Use this expression when a macro will emit an error diagnostic but the + /// compiler still requires us to produce a valid expression. + static var unreachable: Self { + #"Swift.fatalError("Unreachable")"# + } +} diff --git a/Sources/TestingMacros/Support/ClosureCaptureListParsing.swift b/Sources/TestingMacros/Support/ClosureCaptureListParsing.swift index 08536aa69..c4266c99f 100644 --- a/Sources/TestingMacros/Support/ClosureCaptureListParsing.swift +++ b/Sources/TestingMacros/Support/ClosureCaptureListParsing.swift @@ -41,7 +41,7 @@ struct CapturedValueInfo { init(_ capture: ClosureCaptureSyntax, in context: some MacroExpansionContext) { self.capture = capture - self.expression = #"Swift.fatalError("Unsupported")"# + self.expression = .unreachable self.type = "Swift.Never" // We don't support capture specifiers at this time. diff --git a/Sources/TestingMacros/TagMacro.swift b/Sources/TestingMacros/TagMacro.swift index 624f812cd..01932ef5d 100644 --- a/Sources/TestingMacros/TagMacro.swift +++ b/Sources/TestingMacros/TagMacro.swift @@ -22,7 +22,7 @@ public struct TagMacro: PeerMacro, AccessorMacro, Sendable { /// This property is used rather than simply returning the empty array in /// order to suppress a compiler diagnostic about not producing any accessors. private static var _fallbackAccessorDecls: [AccessorDeclSyntax] { - [#"get { Swift.fatalError("Unreachable") }"#] + [#"get { \#(ExprSyntax.unreachable) }"#] } public static func expansion(