Skip to content

Commit ad181b9

Browse files
committed
IRGen: Fix assertion failure with typed throws
The mapTypeIntoContext() call in visitFullApplySite() was not necessary. The type in question is already fully substituted and should no longer contain type parameters. However, it can contain archetypes, which is what caused mapTypeIntoContext() to assert. Indeed, this case where the return type is generic but still loadable wasn't covered by our test suite. - Fixes #80020. - Fixes rdar://147051717.
1 parent b0627e2 commit ad181b9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4040,8 +4040,9 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
40404040
Builder.emitBlock(typedErrorLoadBB);
40414041

40424042
auto &errorTI = cast<LoadableTypeInfo>(IGM.getTypeInfo(errorType));
4043-
auto silResultTy = CurSILFn->mapTypeIntoContext(
4044-
substConv.getSILResultType(IGM.getMaximalTypeExpansionContext()));
4043+
auto silResultTy =
4044+
substConv.getSILResultType(IGM.getMaximalTypeExpansionContext());
4045+
ASSERT(!silResultTy.hasTypeParameter());
40454046
auto &resultTI = cast<LoadableTypeInfo>(IGM.getTypeInfo(silResultTy));
40464047

40474048
auto &resultSchema = resultTI.nativeReturnValueSchema(IGM);

test/IRGen/typed_throws_generic.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-irgen
2+
3+
// https://github.com/swiftlang/swift/issues/80020
4+
//
5+
// We used to assert if you had a loadable return type that contained
6+
// a generic parameter.
7+
8+
public enum MyError: Error {
9+
case error
10+
}
11+
12+
public struct G<T> {} // Note: G<T> is loadable
13+
14+
public func f<T>(t: T) throws(MyError) -> G<T> {
15+
return G<T>()
16+
}
17+
18+
public func g<U>(u: U?) throws(MyError) -> G<U?> {
19+
return try f(t: u)
20+
}

0 commit comments

Comments
 (0)