Skip to content

Commit aa4db79

Browse files
committed
[SILGen]Check if baseType is DynamicSelfType
1 parent 4b5d519 commit aa4db79

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3399,7 +3399,11 @@ static ManagedValue emitKeyPathRValueBase(SILGenFunction &subSGF,
33993399

34003400
// Upcast a class instance to the property's declared type if necessary.
34013401
if (auto propertyClass = storage->getDeclContext()->getSelfClassDecl()) {
3402-
if (baseType->getClassOrBoundGenericClass() != propertyClass) {
3402+
auto baseClass = baseType->getClassOrBoundGenericClass();
3403+
if (auto dynamicSelfType = baseType->getAs<DynamicSelfType>()) {
3404+
baseClass = dynamicSelfType->getSelfType()->getClassOrBoundGenericClass();
3405+
}
3406+
if (baseClass != propertyClass) {
34033407
baseType = baseType->getSuperclassForDecl(propertyClass)
34043408
->getCanonicalType();
34053409
paramSubstValue = subSGF.B.createUpcast(loc, paramSubstValue,

test/SILGen/keypaths.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,24 @@ protocol HasAlias {
805805
func testHasAlias() {
806806
_ = \HasAlias.id
807807
}
808+
809+
// https://github.com/swiftlang/swift/issues/80669
810+
func type<Root, Value>(at keyPath: KeyPath<Root, Value>) -> Value.Type {
811+
return Value.self
812+
}
813+
814+
class DynamicSelfTypeTestClass {
815+
var other = DynamicSelfTypeTestClass()
816+
817+
static func staticFunc() {
818+
type(at: \Self.other).bar()
819+
}
820+
821+
static func bar() {
822+
print("Hello")
823+
}
824+
}
825+
826+
func testDynamicSelfType() {
827+
DynamicSelfTypeTestClass.staticFunc()
828+
}

0 commit comments

Comments
 (0)