Skip to content

Commit 4258fa3

Browse files
authored
Merge pull request #25749 from DougGregor/di-property-wrappers-crash-rdar-51581937-5.1
2 parents 4f7244a + b761dfe commit 4258fa3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,8 @@ namespace {
14091409
SGF.getModule().getSwiftModule(), ctor);
14101410

14111411
Type ity = ctor->getInterfaceType();
1412-
AnyFunctionType *substIty = ity.subst(subs)->castTo<AnyFunctionType>();
1412+
AnyFunctionType *substIty =
1413+
ity.subst(subs)->getCanonicalType()->castTo<AnyFunctionType>();
14131414

14141415
auto initRef = SILDeclRef(ctor, SILDeclRef::Kind::Allocator)
14151416
.asForeign(requiresForeignEntryPoint(ctor));

test/SILOptimizer/di_property_wrappers.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,26 @@ func testDefaultInit() {
346346
// CHECK: set value hello
347347
}
348348

349+
// rdar://problem/51581937: DI crash with a property wrapper of an optional
350+
struct OptIntStruct {
351+
@Wrapper var wrapped: Int?
352+
353+
init() {
354+
wrapped = 42
355+
}
356+
}
357+
358+
func testOptIntStruct() {
359+
// CHECK: ## OptIntStruct
360+
print("\n## OptIntStruct")
361+
362+
let use = OptIntStruct()
363+
// CHECK-NEXT: .. init Optional(42)
364+
}
365+
349366
testIntStruct()
350367
testIntClass()
351368
testRefStruct()
352369
testGenericClass()
353370
testDefaultInit()
371+
testOptIntStruct()

0 commit comments

Comments
 (0)