Skip to content

Commit b8642b0

Browse files
committed
SILGen: Fix crash when immediately-applied closure transitively captures generic parameters
1 parent d3a4f3d commit b8642b0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,15 +1163,16 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
11631163
// really producing a closure object.
11641164
SILDeclRef constant(e);
11651165

1166+
auto captureInfo = SGF.SGM.M.Types.getLoweredLocalCaptures(e);
1167+
11661168
SubstitutionMap subs;
1167-
if (e->getCaptureInfo().hasGenericParamCaptures())
1169+
if (captureInfo.hasGenericParamCaptures())
11681170
subs = SGF.getForwardingSubstitutionMap();
11691171

11701172
setCallee(Callee::forDirect(SGF, constant, subs, e));
11711173

11721174
// If the closure requires captures, emit them.
1173-
bool hasCaptures = SGF.SGM.M.Types.hasLoweredLocalCaptures(e);
1174-
if (hasCaptures) {
1175+
if (!captureInfo.getCaptures().empty()) {
11751176
SmallVector<ManagedValue, 4> captures;
11761177
SGF.emitCaptures(e, e, CaptureEmission::ImmediateApplication,
11771178
captures);

test/SILGen/default_arguments_generic.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,12 @@ func f<T : StaticIntValue>(_: T) {
8383

8484
// CHECK-LABEL: sil private [ossa] @$s25default_arguments_generic1fyyxAA14StaticIntValueRzlF5otherL_yyAaCRzlF : $@convention(thin) <T where T : StaticIntValue> () -> ()
8585
func other() { inner() }
86-
}
86+
}
87+
88+
func g<T>(_: T) {
89+
{ inner() }()
90+
91+
func inner() {
92+
_ = T.self
93+
}
94+
}

0 commit comments

Comments
 (0)