Skip to content

Commit d497e65

Browse files
committed
SILGen: Fix assert when emitting re-abstraction thunk in edge case involving opaque return type
If we can see the underlying type of an opaque return type, and this underlying type does not depend on the opaque return type's generic signature, then we can end up in a situation where the lowered type of a re-abstraction thunk is not generic, but the formal type is. This would trigger an assertion failure. Check both the lowered type and formal type for type parameters to cope with this. - Fixes #86118.
1 parent ea58732 commit d497e65

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3605,7 +3605,9 @@ CanSILFunctionType swift::buildSILFunctionThunkType(
36053605

36063606
if (!capturedEnvs.empty() ||
36073607
expectedType->hasPrimaryArchetype() ||
3608-
sourceType->hasPrimaryArchetype()) {
3608+
sourceType->hasPrimaryArchetype() ||
3609+
(inputSubstType && inputSubstType->hasPrimaryArchetype()) ||
3610+
(outputSubstType && outputSubstType->hasPrimaryArchetype())) {
36093611
// Get the existing generic signature.
36103612
baseGenericSig = fn->getLoweredFunctionType()
36113613
->getInvocationGenericSignature();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-emit-silgen %s
2+
3+
// https://github.com/swiftlang/swift/issues/86118
4+
5+
// The AST type of the thunk depends on the generic signature, but the
6+
// lowered type does not, because we can see the opaque return type's
7+
// underlying type from the expansion point, and it does not involve
8+
// type parameters. Make sure this does not cause us to assert.
9+
10+
public struct G<T> {
11+
public static func f(_: Any, _: Any) -> some Any {
12+
return 123
13+
}
14+
}
15+
16+
public func g<T>(_: T) {
17+
let fn: (Any, Any) -> _ = G<T>.f
18+
let fn2: (Int, Int) -> _ = fn
19+
}

0 commit comments

Comments
 (0)