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

Support For Swift 6 Typed Throws #63

Open
calebwilson706 opened this issue Jul 8, 2024 · 14 comments · May be fixed by #64
Open

Support For Swift 6 Typed Throws #63

calebwilson706 opened this issue Jul 8, 2024 · 14 comments · May be fixed by #64
Labels
bug Something isn't working

Comments

@calebwilson706
Copy link

We recently updated our project to swift 6 and were looking forward to using typed throws. However, Mockable gives us the following error when adding the error type to the functions on our protocol definitions

Invalid variable requirement. Missing type annotation or accessor block.

Example Code

enum ExampleError: Error {
    case myError
}

@Mockable
protocol Example {
    func theFunction() throws(ExampleError)
}
@kelvinharron
Copy link

@Kolos65 would you accept contributions for this? I'd be happy to progress this with some guidance as we're keen to embrace Swift 6. Thanks!

@Kolos65
Copy link
Owner

Kolos65 commented Jul 8, 2024

This is not a library issue, swift-syntax 511.x.x cannot parse this new Swift 6 feature and the throws(ExampleError) is mistaken to a variable declaration somehow.

This can't be fixed until the official realse of swift-syntax 600.x.x which is currently in pre-release phase.

@Kolos65
Copy link
Owner

Kolos65 commented Jul 8, 2024

Regardless, adding support for typed throws will not be trivial, we could start implementing that in the meantime.

@kelvinharron
Copy link

Great context to have on the release, thanks @Kolos65 . Any guidance on how we could start? We're loving our time with Mockable and we're keen to help make it even better where we can. 👍

@Kolos65
Copy link
Owner

Kolos65 commented Jul 8, 2024

I would start this by first making this work with the above protocol's current expansion (remove the typed throw and copy the @Mockable expansion to a source file). After we have a PoC of that, we can implement those changes in the macro.

@Kolos65
Copy link
Owner

Kolos65 commented Jul 8, 2024

Added some pre-work in this PR: #64

@Kolos65 Kolos65 added the bug Something isn't working label Sep 27, 2024
@Kolos65 Kolos65 linked a pull request Sep 27, 2024 that will close this issue
5 tasks
@Kolos65
Copy link
Owner

Kolos65 commented Sep 28, 2024

@calebwilson706, @kelvinharron I have finished implementing this feature, can you guys take a quick look by using the feat-add-typed-throws-support branch?

@kelvinharron
Copy link

I'll get back to you asap on this @Kolos65 thank you for providing it!

@kelvinharron
Copy link

@Kolos65 The flow I tried was to update a protocol to use a typed throw and set a module and its test companion target to use Swift 6. When I look at the Mocker class from Mockable, I don't see it pick up the Swift 6 codeblock.

Screenshot 2024-10-02 at 11 57 23 Screenshot 2024-10-02 at 11 58 33

Do you know what I could be missing here? Instead of creating a new app to test this individually, I'm trying to bring it into our existing app because it would be a real world representation other users would share. Thanks!

@Kolos65
Copy link
Owner

Kolos65 commented Oct 2, 2024

@kelvinharron Can you check if you see:

    swiftLanguageVersions: [.v5, .version("6")]

in the Package.swift of your pulled version?

@kelvinharron
Copy link

@Kolos65 confirmed:

let package = Package(
    name: "Mockable",
    platforms: [.macOS(.v12), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)],
    products: [
        .library(
            name: "Mockable",
            targets: ["Mockable"]
        )
    ],
    dependencies: ifDev(add: devDependencies) + [
        .package(url: "https://github.com/swiftlang/swift-syntax.git", "509.0.0"..<"601.0.0"),
        .package(url: "https://github.com/pointfreeco/swift-issue-reporting", .upToNextMajor(from: "1.4.1"))
    ],
    targets: ifDev(add: devTargets) + [
        .target(
            name: "Mockable",
            dependencies: [
                "MockableMacro",
                .product(name: "IssueReporting", package: "swift-issue-reporting")
            ],
            plugins: ifDev(add: devPlugins)
        ),
        .macro(
            name: "MockableMacro",
            dependencies: [
                .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
                .product(name: "SwiftCompilerPlugin", package: "swift-syntax")
            ],
            plugins: ifDev(add: devPlugins)
        )
    ],
    swiftLanguageVersions: [.v5, .version("6")]
)

While I can get us to Xcode 16 and iOS 18 easily, I'm not sure how long moving to Swift 6 across the codebase will take. Any thoughts on what I can do to further debug? Keen to help with this ace work you've done (and greatly welcome the removal of MockableTest)! 😃

@Kolos65
Copy link
Owner

Kolos65 commented Oct 15, 2024

@kelvinharron so there are other modules that still use swift 5 in the project?

@kelvinharron
Copy link

@Kolos65 yes, it's on our list to migrate them all over. I can't promise a timeline on that with other priorities as we move towards our deadline window. Would you prefer to revisit this another time?

@Kolos65
Copy link
Owner

Kolos65 commented Oct 18, 2024

Yeah, I think if you still have some modules that are built with Swift 5 language mode, Mockable won't be compiled with Swift 6. If you get to a point where you can test this in your project, I would love to hear your feedback! I think I will merge this soon anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants