@@ -3243,7 +3243,8 @@ static PreparedArguments loadIndexValuesForKeyPathComponent(
3243
3243
SILGenFunction &SGF, SILLocation loc, ValueDecl *storage,
3244
3244
ArrayRef<IndexTypePair> indexes, SILValue pointer) {
3245
3245
// If not a subscript or method, do nothing.
3246
- if (!(isa<SubscriptDecl>(storage) || isa<FuncDecl>(storage)))
3246
+ if (!(isa<SubscriptDecl>(storage) || isa<FuncDecl>(storage) ||
3247
+ isa<ConstructorDecl>(storage)))
3247
3248
return PreparedArguments ();
3248
3249
3249
3250
SmallVector<AnyFunctionType::Param, 8 > indexParams;
@@ -4277,7 +4278,7 @@ static void lowerKeyPathMemberIndexTypes(
4277
4278
}
4278
4279
needsGenericContext |= methodSubstTy->hasArchetype ();
4279
4280
processIndicesOrParameters (method->getParameters (), &sig);
4280
- }
4281
+ }
4281
4282
}
4282
4283
4283
4284
static void lowerKeyPathMemberIndexPatterns (
@@ -4350,8 +4351,16 @@ KeyPathPatternComponent SILGenModule::emitKeyPathComponentForDecl(
4350
4351
argPatterns, argEquals, argHash);
4351
4352
}
4352
4353
4353
- auto representative = SILDeclRef (storage, SILDeclRef::Kind::Func,
4354
- /* isForeign*/ storage->isImportAsMember ());
4354
+ SILDeclRef::Kind kind;
4355
+ if (isa<FuncDecl>(storage)) {
4356
+ kind = SILDeclRef::Kind::Func;
4357
+ } else if (isa<ConstructorDecl>(storage)) {
4358
+ kind = SILDeclRef::Kind::Allocator;
4359
+ } else {
4360
+ llvm_unreachable (" Unsupported decl kind" );
4361
+ }
4362
+ SILDeclRef representative (storage, kind,
4363
+ /* isForeign*/ storage->isImportAsMember ());
4355
4364
auto id = getFunction (representative, NotForDefinition);
4356
4365
4357
4366
SILFunction *func = nullptr ;
@@ -4646,8 +4655,9 @@ RValue RValueEmitter::visitKeyPathExpr(KeyPathExpr *E, SGFContext C) {
4646
4655
/* for descriptor*/ false , /* is applied func*/ isApplied));
4647
4656
baseTy = loweredComponents.back ().getComponentType ();
4648
4657
if ((kind == KeyPathExpr::Component::Kind::Member &&
4649
- !dyn_cast<FuncDecl>(decl)) ||
4650
- (dyn_cast<FuncDecl>(decl) && !isApplied))
4658
+ !dyn_cast<FuncDecl>(decl) && !dyn_cast<ConstructorDecl>(decl)) ||
4659
+ ((dyn_cast<FuncDecl>(decl) || dyn_cast<ConstructorDecl>(decl)) &&
4660
+ !isApplied))
4651
4661
break ;
4652
4662
4653
4663
auto loweredArgs = SGF.emitKeyPathOperands (
0 commit comments