diff --git a/lib/SIL/IR/AbstractionPattern.cpp b/lib/SIL/IR/AbstractionPattern.cpp index 59fe0da628ed0..e7913e3b735ca 100644 --- a/lib/SIL/IR/AbstractionPattern.cpp +++ b/lib/SIL/IR/AbstractionPattern.cpp @@ -1366,7 +1366,14 @@ AbstractionPattern::getFunctionThrownErrorType( if (!substErrorType) return std::nullopt; - return std::make_pair(AbstractionPattern(*substErrorType), + // FIXME: This is actually unsound. The most opaque form of + // `(T) throws(U) -> V` should actually be + // `(T) throws(any Error) -> V`. + auto pattern = ((*substErrorType)->isErrorExistentialType() + ? AbstractionPattern(*substErrorType) + : AbstractionPattern::getOpaque()); + + return std::make_pair(pattern, (*substErrorType)->getCanonicalType()); } diff --git a/test/SILGen/keypath_typed_throws.swift b/test/SILGen/keypath_typed_throws.swift new file mode 100644 index 0000000000000..4fc9e02be99b5 --- /dev/null +++ b/test/SILGen/keypath_typed_throws.swift @@ -0,0 +1,8 @@ +// RUN: %target-swift-emit-silgen %s +// RUN: %target-swift-emit-silgen %s -enable-library-evolution +// RUN: %target-swift-emit-silgen %s -enable-testing +// RUN: %target-swift-emit-silgen %s -enable-library-evolution -enable-testing + +public struct Visitor { + public var visit: (Node) throws(Failure) -> Void +}