Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: optional 'any' type must be written '(any Error)?' #1388

Open
vakhidbetrakhmadov opened this issue Dec 8, 2024 · 1 comment
Open

Comments

@vakhidbetrakhmadov
Copy link

vakhidbetrakhmadov commented Dec 8, 2024

Hi

I am facing the following error

// sourcery: MyAutoMockable
protocol UserNotificationCenterProtocol {
    func add(
        _ request: UNNotificationRequest,
        withCompletionHandler completionHandler: (((any Error)?) -> Void)?
    )
}
final class UserNotificationCenterMock: UserNotificationCenterProtocol {
    func add(
        _ request: UNNotificationRequest,
        withCompletionHandler completionHandler: ((any Error?) -> Void)?    // error: optional 'any' type must be written '(any Error)?'
    ) {
        ...
    }
}

{{ method.name }} value

add(_ request: UNNotificationRequest, withCompletionHandler completionHandler: ((any Error?) -> Void)?)

{{ method }} value

<<Method: name = add(_ request: UNNotificationRequest, withCompletionHandler completionHandler: ((any Error?) -> Void)?), selectorName = add(_:withCompletionHandler:), parameters = [MethodParameter: argumentLabel = nil, name = request, typeName = UNNotificationRequest, `inout` = false, isVariadic = false, typeAttributes = [:], defaultValue = nil, annotations = [:], asSource = _ request: UNNotificationRequest, index = 0, MethodParameter: argumentLabel = Optional("withCompletionHandler"), name = completionHandler, typeName = ((any Error?) -> Void)?, `inout` = false, isVariadic = false, typeAttributes = [:], defaultValue = nil, annotations = [:], asSource = withCompletionHandler completionHandler: ((any Error?) -> Void)?, index = 1], returnTypeName = Void, isAsync = false, `throws` = false, `rethrows` = false, accessLevel = internal, isStatic = false, isClass = false, isFailableInitializer = false, annotations = [:], documentation = [], definedInTypeName = Optional(UserNotificationCenterProtocol), attributes = [:], modifiers = [], genericRequirements = [], genericRequirements = []>>

I am using Sourcery 2.2.5 and Xcode 16.

@vakhidbetrakhmadov
Copy link
Author

vakhidbetrakhmadov commented Dec 9, 2024

I currently workaround this issue by applying the following patch

{%- macro fixOptionalAny str -%}
    {{ str|replace:"any (\w+)\?","(any $1)?","regex" }}
{%- endmacro -%}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant