Skip to content

Commit 99c7889

Browse files
committed
IRGen: Fix crash when emitting metadata for enum with @autoclosure case
Fixes <rdar://problem/45962425>, <https://bugs.swift.org/browse/SR-9169>.
1 parent 6903e71 commit 99c7889

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/AST/Decl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5890,9 +5890,14 @@ Type EnumElementDecl::getArgumentInterfaceType() const {
58905890

58915891
auto funcTy = interfaceType->castTo<AnyFunctionType>();
58925892
funcTy = funcTy->getResult()->castTo<FunctionType>();
5893-
return AnyFunctionType::composeInput(funcTy->getASTContext(),
5894-
funcTy->getParams(),
5895-
/*canonicalVararg=*/false);
5893+
5894+
auto &ctx = getASTContext();
5895+
SmallVector<TupleTypeElt, 4> elements;
5896+
for (const auto &param : funcTy->getParams()) {
5897+
Type eltType = param.getParameterType(/*canonicalVararg=*/false, &ctx);
5898+
elements.emplace_back(eltType, param.getLabel());
5899+
}
5900+
return TupleType::get(elements, ctx);
58965901
}
58975902

58985903
EnumCaseDecl *EnumElementDecl::getParentCase() const {

test/IRGen/enum_function_payload.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ enum Multi {
1414
case F((Multi) -> ())
1515
case G((Multi) -> ())
1616
}
17+
18+
enum Autoclosure<T> {
19+
case first(@autoclosure () -> Bool, T)
20+
case second(Int, @autoclosure () -> T)
21+
}
22+
23+
_ = Autoclosure.first(false, 3)
24+
_ = Autoclosure.second(3, "hi")

0 commit comments

Comments
 (0)