-
Notifications
You must be signed in to change notification settings - Fork 41
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
Fix #52 - Support generic functions #71
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #71 +/- ##
==========================================
+ Coverage 98.41% 98.72% +0.30%
==========================================
Files 18 20 +2
Lines 631 940 +309
==========================================
+ Hits 621 928 +307
- Misses 10 12 +2 ☔ View full report in Codecov by Sentry. |
return cast.nestedTypeSyntaxes | ||
} | ||
// Return an empty array for unsupported types | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing this, we could throw an error, but this would result in error propagation that could ends at forceCastType
in FunctionDeclSyntax+Extension.swift
by having that return nil. If we wanted to take it even further, we could continue propagating all the way to the top of the Spy factory and emit a diagnostic as well.
I'm just not sure if this is worth the trouble and adding throws
everywhere, as I think the only situation that'd reach this code path is if this computed var is triggered on a MissingTypeSyntax
, and in that case, I think returning an empty array would probably be fine.
The same applies to erasingGenericTypes()
below.
@Matejkob Just a heads up, after my other two PRs get in, I’ll likely take another look at self-reviewing this PR with a bit of a fresh take having given this some time. |
@dafurman, thanks for the heads-up! I appreciate your willingness to revisit the PR with fresh eyes — it often brings new insights. Your idea to streamline the PR by postponing certain features, like the parameter packs implementation, sounds like a smart approach to maintain manageability. It's usually better to focus on getting the more stable parts merged first and then iterate. I look forward to seeing the refined PR and am happy to help review or brainstorm further reductions if needed. |
a8e96fd
to
aae5719
Compare
@Matejkob Alrighty I think I've simplified my approach as much as I'm able to right now. It's still quite a bit of code, so no rush on getting to this, I totally understand it's a lot to review! The main meat of the changes is in TypeSyntax+Extensions.swift, with most of the rest of the code changes being added to support additions in this file. To shrink the changes down from my original approach, to make this more reviewable, I also culled syntax types being initially supported for generics down to these, which I think ought to be enough for demonstrating how we can support generics in a fairly modular way. I can add in more types as a followup PR if we're happy with this approach. |
f0746c8
to
d509c7f
Compare
d509c7f
to
b5267c0
Compare
# Conflicts: # Examples/Sources/ViewModel.swift # Sources/SpyableMacro/Factories/ClosureFactory.swift # Tests/SpyableMacroTests/Factories/UT_ClosureFactory.swift # Tests/SpyableMacroTests/Factories/UT_ReceivedArgumentsFactory.swift # Tests/SpyableMacroTests/Factories/UT_SpyFactory.swift
b728a48
to
7e794c8
Compare
Today, the following code
will produce
Spy that doesn't compile
This PR adds support for generic functions by having stored properties retain generic types as
Any
, generating this instead:Spy that compiles
More information and guidance about this has been added to the README in this PR as well.
This PR has already gotten really large, but I'm interested in these followup improvements:
For example, something like this:
Any
with generic constraints where possible, to ease use when you only need to refer to the generic by its constraint. This is described well by @arennow here.