Skip to content

Commit 7f222b0

Browse files
authored
Merge pull request #81162 from slavapestov/fix-issue-74289
SILGen: Fix crash when thrown error type is loadable and has a type parameter
2 parents 86c30d6 + 7285a9b commit 7f222b0

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

lib/SIL/IR/SILArgument.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SILArgument::SILArgument(ValueKind subClassKind,
3737
sharedUInt8().SILArgument.reborrow = reborrow;
3838
sharedUInt8().SILArgument.pointerEscape = pointerEscape;
3939
inputParentBlock->insertArgument(inputParentBlock->args_end(), this);
40+
ASSERT(!type.hasTypeParameter());
4041
}
4142

4243
SILFunction *SILArgument::getFunction() {

lib/SILGen/SILGenEpilog.cpp

Lines changed: 3 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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)