-
-
Notifications
You must be signed in to change notification settings - Fork 624
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
Feature/typed throws support #1401
Merged
krzysztofzablocki
merged 15 commits into
krzysztofzablocki:master
from
alexandre-pod:feature/typed_throws_support
Feb 18, 2025
Merged
Feature/typed throws support #1401
krzysztofzablocki
merged 15 commits into
krzysztofzablocki:master
from
alexandre-pod:feature/typed_throws_support
Feb 18, 2025
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This Linux crash is due to the encoding/decoding operation done with NSArchiver in Sourcery.swift (where requiresFileParserCopy is used) This crash is due to an infinite loop while decoding nested Type because of a cycle between Type and itself (containedTypes / parent), also Type and Typealias have the same issue
great work, thank you🙇 |
Hi, first of all, thanks for merging this PR! I was wondering when the next release including these changes is planned. Do you have an estimated date for it? Thanks in advance! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR solves #1371 by adding basic support for Typed Throws (SE-0413) introduced with Swift 6 and usable without Swift 6 language mode.
Here a recap of what has been added to support typed throws:
throwsTypeName
toMethod
,Variable
,Subscript
andClosure
to expose the optional throws typeisThrowsTypeGeneric
toMethod
, to tell if the thrown type error is a generic parameterisNever
onTypeName
to facilitate the handling ofthrows(Never)
Usage example
Protocol we want to mock
Generated code from AutoMockable
Mock usage example:
Limitations
func doOrRethrows<E>(_ block: () throws(E) -> Void) throws(E) -> Int where E: Error
are not supported as handling those error types are not easy. Also The where clause was causing me an issue because it was included in the return type, this causing issues with generated variables used to control mock behavior.init<E>() throws(E) where E: Error
, for the same reason as MethodsEven if those limitation does not allow complete configuration of mocked methods, this makes possible the generation of a mock class that still allow compilation. Those limitations can be managed manually by subclassing the generated mock for now, and it should be possible to handle that in AutoMockable but right now it is too much work for me.
If in the future we want to support those generic types, an approach could be to attempt the generation of this code:
This is NOT what is proposed in this Pull Request, but may be useful for a future evolution