Handle any Error and Never thrown error types during runtime uniquing.

When forming runtime metadata for a function type that has either `any
Error` or `Never` as the specified thrown error type, drop the thrown
error type and normalize down to (untyped) `throws` or non-throwing,
as appropriate.
This commit is contained in:
Doug Gregor
2023-10-29 19:29:09 -07:00
parent a5f41ce266
commit 1b42ca3673
2 changed files with 73 additions and 1 deletions

View File

@@ -526,12 +526,26 @@ enum MyBigError: Error {
case epicFail
}
@available(SwiftStdlib 5.11, *)
func getFnTypeWithThrownError<E: Error>(_: E.Type) -> Any.Type {
typealias Fn = (Int) throws(E) -> Void
return Fn.self
}
if #available(SwiftStdlib 5.11, *) {
DemangleToMetadataTests.test("typed throws") {
typealias Fn = (Int) throws(MyBigError) -> Void
expectEqual("ySi4main10MyBigErrorOYKc", _mangledTypeName(Fn.self)!)
print("Looking up the typed throws... \(_typeByName("ySi4main10MyBigErrorOYKc"))")
expectEqual(Fn.self, _typeByName("ySi4main10MyBigErrorOYKc")!)
expectEqual(getFnTypeWithThrownError(MyBigError.self), _typeByName("ySi4main10MyBigErrorOYKc")!)
// throws(any Error) -> throws
expectEqual(getFnTypeWithThrownError((any Error).self), _typeByName("ySiKc")!)
// throws(Never) -> non-throwing
expectEqual(getFnTypeWithThrownError(Never.self), _typeByName("ySic")!)
}
}