SILGen: Fix crash when thrown error type is loadable and has a type parameter

Fixes https://github.com/swiftlang/swift/issues/74289.
Fixes rdar://problem/146677409.
This commit is contained in:
Slava Pestov
2025-04-29 10:48:20 -04:00
parent 5d36643af4
commit 63afeb4f48
2 changed files with 10 additions and 1 deletions

View File

@@ -83,10 +83,12 @@ void SILGenFunction::prepareEpilog(
void SILGenFunction::prepareRethrowEpilog(
DeclContext *dc, AbstractionPattern origErrorType, Type errorType,
CleanupLocation cleanupLoc) {
ASSERT(!errorType->hasPrimaryArchetype());
SILBasicBlock *rethrowBB = createBasicBlock(FunctionSection::Postmatter);
if (!IndirectErrorResult) {
SILType loweredErrorType = getLoweredType(origErrorType, errorType);
auto errorTypeInContext = dc->mapTypeIntoContext(errorType);
SILType loweredErrorType = getLoweredType(origErrorType, errorTypeInContext);
rethrowBB->createPhiArgument(loweredErrorType, OwnershipKind::Owned);
}

View File

@@ -387,3 +387,10 @@ extension ReducedError where T == MyError {
throw MyError.fail
}
}
// https://github.com/swiftlang/swift/issues/74289
struct LoadableGeneric<E>: Error {}
func throwsLoadableGeneric<E>(_: E) throws(LoadableGeneric<E>) {
throw LoadableGeneric<E>()
}