From f2070d44598abfff876e12b278b4bcefa2211b20 Mon Sep 17 00:00:00 2001 From: David Roman <2538074+davdroman@users.noreply.github.com> Date: Thu, 3 Sep 2026 03:06:50 +0100 Subject: [PATCH] fix(swizzling): deprecate single-parameter overloads Direct callers to the variadic params overload now that single-element packs type-check correctly. Update package examples and runtime coverage to use the canonical spelling. --- README.md | 2 +- Sources/Swizzling/Macros.swift | 28 ++----------------------- Tests/SwizzlingTests/SwizzleTests.swift | 4 ++-- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 856e022..e9f50ed 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ try #swizzle(UIViewController.viewDidLoad) { $self in print("After") } -try #swizzle(UIViewController.viewDidAppear, param: Bool.self) { $self, animated in +try #swizzle(UIViewController.viewDidAppear, params: Bool.self) { $self, animated in print("Before") self.viewDidAppear(animated) print("After") diff --git a/Sources/Swizzling/Macros.swift b/Sources/Swizzling/Macros.swift index 82877ff..9316b15 100644 --- a/Sources/Swizzling/Macros.swift +++ b/Sources/Swizzling/Macros.swift @@ -20,19 +20,7 @@ public macro swizzle( // MARK: Functions - Non Returning -// NOTE: this is only needed because some weird behavior in the compiler causes the variadic -// version below to throw a false positive error when passing a single param under very specific -// conditions. This version is a workaround that can be used in those cases. -// -// Reproducible case: -// ```swift -// try #swizzle( -// SUT.functionWithParamsWithoutReturn, -// params: Int.self -// ) { $self, state in -// self.functionWithParamsWithoutReturn(state) // 🛑 error: Cannot pass value pack expansion to non-pack parameter of type 'Int' -// } -// ``` +@available(*, deprecated, renamed: "swizzle(_:params:implementation:)") @discardableResult @freestanding(expression) public macro swizzle( @@ -51,19 +39,7 @@ public macro swizzle( // MARK: Functions - Returning -// NOTE: this is only needed because some weird behavior in the compiler causes the variadic -// version below to throw a false positive error when passing a single param under very specific -// conditions. This version is a workaround that can be used in those cases. -// -// Reproducible case: -// ```swift -// try #swizzle( -// SUT.functionWithParamsWithReturn, -// params: Int.self, -// returning: Int.self -// ) { $self, state in -// self.functionWithParamsWithReturn(state) // 🛑 error: Cannot pass value pack expansion to non-pack parameter of type 'Int' -// } +@available(*, deprecated, renamed: "swizzle(_:params:returning:implementation:)") @discardableResult @freestanding(expression) public macro swizzle( diff --git a/Tests/SwizzlingTests/SwizzleTests.swift b/Tests/SwizzlingTests/SwizzleTests.swift index f83d391..ae7b3bd 100644 --- a/Tests/SwizzlingTests/SwizzleTests.swift +++ b/Tests/SwizzlingTests/SwizzleTests.swift @@ -111,7 +111,7 @@ extension SwizzleTests { func `swizzle function with parameters and without a return value`() throws { let hook = try #swizzle( SUT.functionWithParamsWithoutReturn, - param: Int.self, + params: Int.self, ) { $self, state in self.functionWithParamsWithoutReturn(state + 1) } @@ -130,7 +130,7 @@ extension SwizzleTests { func `swizzle function with parameters and a return value`() throws { let hook = try #swizzle( SUT.functionWithParamsWithReturn, - param: Int.self, + params: Int.self, returning: Int.self, ) { $sut, value in sut.functionWithParamsWithReturn(value + 1)