Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unimplemented support for typed throws #117

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- ``unimplemented(_:fileID:filePath:function:line:column:)-2ae22``
- ``unimplemented(_:fileID:filePath:function:line:column:)-1hsov``
- ``unimplemented(_:throwing:fileID:filePath:function:line:column:)-4h958``
- ``unimplemented(_:throwing:fileID:filePath:function:line:column:)-5zfy9``
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-6ts5j``
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-34tpp``

Expand Down
84 changes: 84 additions & 0 deletions Sources/IssueReporting/Unimplemented.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,47 @@ public func unimplemented<each Argument, Result>(
}
}

#if compiler(>=6)
/// Returns a throwing closure that reports an issue and throws a given error when invoked.
///
/// Useful for creating closures that need to be overridden by users of your API, and if it is
/// ever invoked without being overridden an issue will be reported. See
/// <doc:GettingStarted#Unimplemented-closures> for more information.
///
/// - Parameters:
/// - description: An optional description of the unimplemented closure.
/// - failure: The error thrown by the unimplemented closure.
/// - fileID: The fileID.
/// - filePath: The filePath.
/// - function: The function.
/// - line: The line.
/// - column: The column.
/// - Returns: A throwing closure that reports an issue and throws an error when invoked.
public func unimplemented<each Argument, Failure: Error, Result>(
_ description: @autoclosure @escaping @Sendable () -> String = "",
throwing failure: @autoclosure @escaping @Sendable () -> Failure,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
function: StaticString = #function,
line: UInt = #line,
column: UInt = #column
) -> @Sendable (repeat each Argument) throws(Failure) -> Result {
return { (argument: repeat each Argument) throws(Failure) in
let description = description()
_fail(
description,
(repeat each argument),
fileID: fileID,
filePath: filePath,
function: function,
line: line,
column: column
)
throw failure()
}
}
#endif

/// Returns an asynchronous closure that reports an issue when invoked.
///
/// Useful for creating closures that need to be overridden by users of your API, and if it is
Expand Down Expand Up @@ -149,6 +190,49 @@ public func unimplemented<each Argument, Result>(
}
}

#if compiler(>=6)
/// Returns a throwing, asynchronous closure that reports an issue and throws a given error when
/// invoked.
///
/// Useful for creating closures that need to be overridden by users of your API, and if it is
/// ever invoked without being overridden an issue will be reported. See
/// <doc:GettingStarted#Unimplemented-closures> for more information.
///
/// - Parameters:
/// - description: An optional description of the unimplemented closure.
/// - failure: The error thrown by the unimplemented closure.
/// - fileID: The fileID.
/// - filePath: The filePath.
/// - function: The function.
/// - line: The line.
/// - column: The column.
/// - Returns: A throwing, asynchronous closure that reports an issue and throws an error when
/// invoked.
public func unimplemented<each Argument, Failure: Error, Result>(
_ description: @autoclosure @escaping @Sendable () -> String = "",
throwing failure: @autoclosure @escaping @Sendable () -> Failure,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
function: StaticString = #function,
line: UInt = #line,
column: UInt = #column
) -> @Sendable (repeat each Argument) async throws(Failure) -> Result {
return { (argument: repeat each Argument) async throws(Failure) in
let description = description()
_fail(
description,
(repeat each argument),
fileID: fileID,
filePath: filePath,
function: function,
line: line,
column: column
)
throw failure()
}
}
#endif

@_disfavoredOverload
public func unimplemented<Result>(
_ description: @autoclosure @escaping @Sendable () -> String = "",
Expand Down