Skip to content

Commit 88cad6b

Browse files
authored
[SIL] Look through optionals in an unowned type's referent type during type classification (swiftlang#32927)
1 parent 4394e92 commit 88cad6b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ namespace {
392392
} \
393393
RetTy visit##Name##StorageType(Can##Name##StorageType type, \
394394
AbstractionPattern origType) { \
395-
auto referentType = type->getReferentType(); \
395+
auto referentType = \
396+
type->getReferentType()->lookThroughSingleOptionalType(); \
396397
auto concreteType = getConcreteReferenceStorageReferent(referentType); \
397398
if (Name##StorageType::get(concreteType, TC.Context) \
398399
->isLoadable(Expansion.getResilienceExpansion())) { \

test/SILGen/unowned.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,13 @@ func takesUnownedStruct(_ z: Unowned<C>) {}
161161
// Make sure we don't crash here
162162
struct UnownedGenericCapture<T : AnyObject> {
163163
var object: T
164+
var optionalObject: T?
164165

165166
func f() -> () -> () {
166167
return { [unowned object] in _ = object }
167168
}
169+
170+
func g() -> () -> () {
171+
return { [unowned optionalObject] in _ = optionalObject }
172+
}
168173
}

0 commit comments

Comments
 (0)