From 72bfce316bc0c434a970d0d0a18d40c9b73cdfcd Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Tue, 9 Jan 2024 19:40:32 +0000 Subject: [PATCH] Trim exclamation mark from assign-only property types --- Sources/Shared/PropertyTypeSanitizer.swift | 2 +- .../testRetainsAssignOnlyPropertyTypes.swift | 2 ++ Tests/PeripheryTests/RetentionTest.swift | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/Shared/PropertyTypeSanitizer.swift b/Sources/Shared/PropertyTypeSanitizer.swift index bcd878d81..efcc3847b 100644 --- a/Sources/Shared/PropertyTypeSanitizer.swift +++ b/Sources/Shared/PropertyTypeSanitizer.swift @@ -8,6 +8,6 @@ public struct PropertyTypeSanitizer { @inlinable public static func sanitize(_ type: String) -> String { - type.trimmed.trimmingCharacters(in: .init(["?"])) + type.trimmed.trimmingCharacters(in: .init(["?", "!"])) } } diff --git a/Tests/Fixtures/RetentionFixtures/testRetainsAssignOnlyPropertyTypes.swift b/Tests/Fixtures/RetentionFixtures/testRetainsAssignOnlyPropertyTypes.swift index 1c8ea5339..94c116d7e 100644 --- a/Tests/Fixtures/RetentionFixtures/testRetainsAssignOnlyPropertyTypes.swift +++ b/Tests/Fixtures/RetentionFixtures/testRetainsAssignOnlyPropertyTypes.swift @@ -6,6 +6,7 @@ public class FixtureClass123 { struct CustomType {} var retainedSimpleProperty: CustomType? + var retainedSimplePropertyImplicitUnwrap: CustomType! var notRetainedSimpleProperty: String? var retainedModulePrefixedProperty: Swift.Double? var notRetainedModulePrefixedProperty: Swift.Bool? @@ -20,6 +21,7 @@ public class FixtureClass123 { public func someFunc() { retainedSimpleProperty = CustomType() + retainedSimplePropertyImplicitUnwrap = CustomType() notRetainedSimpleProperty = "" retainedModulePrefixedProperty = 1 diff --git a/Tests/PeripheryTests/RetentionTest.swift b/Tests/PeripheryTests/RetentionTest.swift index aefb13bc3..ff0c60d7a 100644 --- a/Tests/PeripheryTests/RetentionTest.swift +++ b/Tests/PeripheryTests/RetentionTest.swift @@ -1150,10 +1150,22 @@ final class RetentionTest: FixtureSourceGraphTestCase { analyze(retainPublic: true) { assertReferenced(.class("FixtureClass123")) { self.assertReferenced(.varInstance("retainedSimpleProperty")) + self.assertNotAssignOnlyProperty(.varInstance("retainedSimpleProperty")) + + self.assertReferenced(.varInstance("retainedSimplePropertyImplicitUnwrap")) + self.assertNotAssignOnlyProperty(.varInstance("retainedSimplePropertyImplicitUnwrap")) + self.assertReferenced(.varInstance("retainedModulePrefixedProperty")) + self.assertNotAssignOnlyProperty(.varInstance("retainedModulePrefixedProperty")) + self.assertReferenced(.varInstance("retainedTupleProperty")) + self.assertNotAssignOnlyProperty(.varInstance("retainedTupleProperty")) + self.assertReferenced(.varInstance("retainedDestructuredPropertyA")) + self.assertNotAssignOnlyProperty(.varInstance("retainedDestructuredPropertyA")) + self.assertReferenced(.varInstance("retainedMultipleBindingPropertyA")) + self.assertNotAssignOnlyProperty(.varInstance("retainedMultipleBindingPropertyA")) #if canImport(Combine) self.assertReferenced(.varInstance("retainedAnyCancellable"))