Skip to content

Commit 519df89

Browse files
authored
Merge pull request #61936 from slavapestov/opened-archetype-keypath-descriptor
IRGen: Workaround for inadvertent mangling of opened archetypes in keypath descriptors
2 parents 3c4dd9f + 1f412a3 commit 519df89

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/IRGen/GenKeyPath.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,15 @@ emitKeyPathComponent(IRGenModule &IGM,
887887
componentCanSig, [&](GenericRequirement reqt) {
888888
auto substType =
889889
reqt.TypeParameter.subst(subs)->getCanonicalType();
890+
891+
// FIXME: This seems wrong. We used to just mangle opened archetypes as
892+
// their interface type. Let's make that explicit now.
893+
substType = substType.transformRec([](Type t) -> Optional<Type> {
894+
if (auto *openedExistential = t->getAs<OpenedArchetypeType>())
895+
return openedExistential->getInterfaceType();
896+
return None;
897+
})->getCanonicalType();
898+
890899
if (!reqt.Protocol) {
891900
// Type requirement.
892901
externalSubArgs.push_back(emitMetadataTypeRefForKeyPath(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@objc public protocol P {}
2+
3+
extension P {
4+
public var value: Bool { true }
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %S/Inputs/keypath_objc_protocol_extension_other.swift -emit-module-path %t/keypath_objc_protocol_extension_other.swiftmodule -disable-objc-attr-requires-foundation-module
3+
// RUN: %target-swift-frontend -emit-ir %s -I %t
4+
5+
// REQUIRES: objc_interop
6+
7+
import keypath_objc_protocol_extension_other
8+
9+
public func foo(array: [any P]) {
10+
_ = array.filter(\.value)
11+
}

0 commit comments

Comments
 (0)