From c0bb33483db8ea05e657eaaeaa2094fe2e3d3bcf Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Tue, 25 Jun 2019 08:53:44 -0700 Subject: [PATCH] [Property wrappers] Make sure to canonicalize a type properly in DI. Fixes a crash/assertion involving sugared types rdar://problem/51581937. --- lib/SILGen/SILGenLValue.cpp | 3 ++- test/SILOptimizer/di_property_wrappers.swift | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/SILGen/SILGenLValue.cpp b/lib/SILGen/SILGenLValue.cpp index f2e9d6bd414..c04652ec9d9 100644 --- a/lib/SILGen/SILGenLValue.cpp +++ b/lib/SILGen/SILGenLValue.cpp @@ -1412,7 +1412,8 @@ namespace { SGF.getModule().getSwiftModule(), ctor); Type ity = ctor->getInterfaceType(); - AnyFunctionType *substIty = ity.subst(subs)->castTo(); + AnyFunctionType *substIty = + ity.subst(subs)->getCanonicalType()->castTo(); auto initRef = SILDeclRef(ctor, SILDeclRef::Kind::Allocator) .asForeign(requiresForeignEntryPoint(ctor)); diff --git a/test/SILOptimizer/di_property_wrappers.swift b/test/SILOptimizer/di_property_wrappers.swift index 0a21ed34923..5abee32e84c 100644 --- a/test/SILOptimizer/di_property_wrappers.swift +++ b/test/SILOptimizer/di_property_wrappers.swift @@ -346,8 +346,26 @@ func testDefaultInit() { // CHECK: set value hello } +// rdar://problem/51581937: DI crash with a property wrapper of an optional +struct OptIntStruct { + @Wrapper var wrapped: Int? + + init() { + wrapped = 42 + } +} + +func testOptIntStruct() { + // CHECK: ## OptIntStruct + print("\n## OptIntStruct") + + let use = OptIntStruct() + // CHECK-NEXT: .. init Optional(42) +} + testIntStruct() testIntClass() testRefStruct() testGenericClass() testDefaultInit() +testOptIntStruct()