SIL: Compute canonical type earlier

This commit is contained in:
Slava Pestov
2024-08-17 14:27:03 -04:00
parent be56e430ca
commit 66cd708a16
2 changed files with 12 additions and 5 deletions

View File

@@ -2012,22 +2012,22 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
auto options = SILParameterInfo::Options();
Type type;
CanType type;
VarDecl *varDecl = nullptr;
if (auto *expr = capture.getPackElement()) {
type = expr->getType();
type = expr->getType()->getCanonicalType();
} else {
varDecl = cast<VarDecl>(capture.getDecl());
type = varDecl->getTypeInContext();
type = varDecl->getTypeInContext()->getCanonicalType();
// If we're capturing a parameter pack, wrap it in a tuple.
if (type->is<PackExpansionType>()) {
if (isa<PackExpansionType>(type)) {
assert(!cast<ParamDecl>(varDecl)->supportsMutation() &&
"Cannot capture a pack as an lvalue");
SmallVector<TupleTypeElt, 1> elts;
elts.push_back(type);
type = TupleType::get(elts, TC.Context);
type = CanType(TupleType::get(elts, TC.Context));
}
if (isolatedParam == varDecl) {

View File

@@ -18,3 +18,10 @@ protocol P {
func test1(p: any P) -> [Int] {
return p.x.f { $0.y }
}
func callee(_: () -> ()) {}
func test2(p: any P) {
let a = p.x
callee { _ = a }
}