Skip to content

Commit 89ab18c

Browse files
committed
SILGen: Fix crash when thrown error type is loadable and has a type parameter
Fixes swiftlang#74289. Fixes rdar://problem/146677409.
1 parent e3d8e35 commit 89ab18c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/SILGen/SILGenEpilog.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ void SILGenFunction::prepareEpilog(
8383
void SILGenFunction::prepareRethrowEpilog(
8484
DeclContext *dc, AbstractionPattern origErrorType, Type errorType,
8585
CleanupLocation cleanupLoc) {
86+
ASSERT(!errorType->hasPrimaryArchetype());
8687

8788
SILBasicBlock *rethrowBB = createBasicBlock(FunctionSection::Postmatter);
8889
if (!IndirectErrorResult) {
89-
SILType loweredErrorType = getLoweredType(origErrorType, errorType);
90+
auto errorTypeInContext = dc->mapTypeIntoContext(errorType);
91+
SILType loweredErrorType = getLoweredType(origErrorType, errorTypeInContext);
9092
rethrowBB->createPhiArgument(loweredErrorType, OwnershipKind::Owned);
9193
}
9294

test/SILGen/typed_throws_generic.swift

+7
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,10 @@ extension ReducedError where T == MyError {
387387
throw MyError.fail
388388
}
389389
}
390+
391+
// https://github.com/swiftlang/swift/issues/74289
392+
struct LoadableGeneric<E>: Error {}
393+
394+
func throwsLoadableGeneric<E>(_: E) throws(LoadableGeneric<E>) {
395+
throw LoadableGeneric<E>()
396+
}

0 commit comments

Comments
 (0)