Skip to content

Commit 74b2b03

Browse files
committed
SILGen: Don't ask for context substitution map of existential
1 parent abbc37e commit 74b2b03

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4244,19 +4244,25 @@ SILGenModule::emitKeyPathComponentForDecl(SILLocation loc,
42444244
CanType componentTy;
42454245
if (!var->getDeclContext()->isTypeContext()) {
42464246
componentTy = var->getInterfaceType()->getCanonicalType();
4247+
} else if (var->getDeclContext()->getSelfProtocolDecl() &&
4248+
baseTy->isExistentialType()) {
4249+
componentTy = var->getValueInterfaceType()->getCanonicalType();
4250+
ASSERT(!componentTy->hasTypeParameter());
42474251
} else {
4248-
componentTy =
4252+
// The mapTypeIntoContext() / mapTypeOutOfContext() dance is there
4253+
// to handle the case where baseTy being a type parameter subject
4254+
// to a superclass requirement.
4255+
componentTy = var->getValueInterfaceType().subst(
42494256
GenericEnvironment::mapTypeIntoContext(genericEnv, baseTy)
4250-
->getTypeOfMember(var)
4251-
->getReferenceStorageReferent()
4257+
->getContextSubstitutionMap(var->getDeclContext()))
42524258
->mapTypeOutOfContext()
42534259
->getCanonicalType();
4260+
}
42544261

4255-
// The component type for an @objc optional requirement needs to be
4256-
// wrapped in an optional.
4257-
if (var->getAttrs().hasAttribute<OptionalAttr>()) {
4258-
componentTy = OptionalType::get(componentTy)->getCanonicalType();
4259-
}
4262+
// The component type for an @objc optional requirement needs to be
4263+
// wrapped in an optional.
4264+
if (var->getAttrs().hasAttribute<OptionalAttr>()) {
4265+
componentTy = OptionalType::get(componentTy)->getCanonicalType();
42604266
}
42614267

42624268
if (canStorageUseStoredKeyPathComponent(var, expansion)) {

test/SILGen/keypaths.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,3 +677,12 @@ func test_optional_chaining_with_function_conversion() {
677677
_ = data.compactMap(\.elements!.db)
678678
}
679679
}
680+
681+
protocol HasAlias {
682+
var id: Self.ID { get }
683+
typealias ID = Int
684+
}
685+
686+
func testHasAlias() {
687+
_ = \HasAlias.id
688+
}

0 commit comments

Comments
 (0)