You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any supported toolchain — the defect is in macro expansion logic and is toolchain-independent.
Package Version
main (observed on the feature/subscript-support branch).
Bug Description
A member declared with an unnamed parameter (a wildcard _ with no internal name) generates an invalid backing body. Both macros derive the forwarded argument from parameter.secondName ?? parameter.firstName, which resolves to the wildcard token _ when there is no internal name, so the generated code forwards _ as an expression — which is not legal Swift ('_' can only appear in a pattern or on the left side of an assignment).
This affects both the subscript and method macros (confirmed — see Compiler verification below):
@_MockedSubscript — keyArgumentExpression(from:) in MockedSubscriptMacro+AccessorMacro.swift.
@_MockedMethod — parameter.secondName ?? parameter.firstName in MockedMethodMacro+BodyMacro.swift (~line 72). The method case emits _ in two places (the recordInput tuple and the _invoke(...) call).
Found during review of the subscript-support feature (#184).
Steps to Reproduce
Mock a protocol with a subscript or method whose parameter has no internal name:
The generated backing body should reference a synthesized parameter name (e.g. bind the wildcard to a generated identifier in the signature, or synthesize a name like arg0), producing compilable code such as self.__subscriptIndex.get(arg0) and _invoke(arg0).
Actual Behavior
Both macros reference the wildcard _ directly, which does not compile.
Surfaced during the code review for Add subscript support #184. Low real-world frequency (subscripts/methods are usually declared with named parameters), so it is filed as a follow-up rather than blocking the feature.
Since both macros share the same secondName ?? firstName forwarding pattern, a fix should cover both — ideally via a shared helper that synthesizes a stable name for wildcard parameters.
Compiler verification
Both halves of the bug were confirmed against the Swift compiler (swiftc -typecheck), not just the macros' (parse-only) test harness:
The inputs are valid Swift. An unnamed parameter typechecks cleanly as both a protocol requirement and a concrete implementation, for subscripts and methods:
Swift Version
Any supported toolchain — the defect is in macro expansion logic and is toolchain-independent.
Package Version
main(observed on thefeature/subscript-supportbranch).Bug Description
A member declared with an unnamed parameter (a wildcard
_with no internal name) generates an invalid backing body. Both macros derive the forwarded argument fromparameter.secondName ?? parameter.firstName, which resolves to the wildcard token_when there is no internal name, so the generated code forwards_as an expression — which is not legal Swift ('_' can only appear in a pattern or on the left side of an assignment).This affects both the subscript and method macros (confirmed — see Compiler verification below):
@_MockedSubscript—keyArgumentExpression(from:)inMockedSubscriptMacro+AccessorMacro.swift.@_MockedMethod—parameter.secondName ?? parameter.firstNameinMockedMethodMacro+BodyMacro.swift(~line 72). The method case emits_in two places (therecordInputtuple and the_invoke(...)call).Found during review of the subscript-support feature (#184).
Steps to Reproduce
Mock a protocol with a subscript or method whose parameter has no internal name:
Expected Behavior
The generated backing body should reference a synthesized parameter name (e.g. bind the wildcard to a generated identifier in the signature, or synthesize a name like
arg0), producing compilable code such asself.__subscriptIndex.get(arg0)and_invoke(arg0).Actual Behavior
Both macros reference the wildcard
_directly, which does not compile.Subscript (
subscript(_: Int) -> String, read-only):Method (
func foo(_: Int) -> String):Stack Trace / Logs
Additional Context
Sources/MockingMacros/Macros/MockedSubscriptMacro/MockedSubscriptMacro+AccessorMacro.swift—keyArgumentExpression(from:).Sources/MockingMacros/Macros/MockedMethodMacro/MockedMethodMacro+BodyMacro.swift—parameter.secondName ?? parameter.firstName(~line 72).secondName ?? firstNameforwarding pattern, a fix should cover both — ideally via a shared helper that synthesizes a stable name for wildcard parameters.Compiler verification
Both halves of the bug were confirmed against the Swift compiler (
swiftc -typecheck), not just the macros' (parse-only) test harness:The inputs are valid Swift. An unnamed parameter typechecks cleanly as both a protocol requirement and a concrete implementation, for subscripts and methods:
The generated output is invalid Swift. Forwarding
_as a call argument is a hard compile error:So a legal protocol declaration produces a mock that fails to compile, for both subscripts and methods.