-
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
Spy on protocol that confirms another protocol #47
Comments
Hi @alpha-moisol, Thank you for bringing up this idea! Ideally, the I have a few strategies in mind to tackle this challenge, and I'm open to further discussion or fresh perspectives.
I'm looking forward to your thoughts on these options! |
@dafurman If you would find a while I would love to hear your opinion on this issue |
@Matejkob I found 2nd and 3rd approaches valid, but do not quite understand how it can be implemented, cause as you said we have only access to the AST node, so we cannot access |
@alpha-moisol, I might not have articulated my idea clearly—my apologies. The advantage here is that spies are classes, which allows for overriding. Consider the following example: @Spyable
protocol A {
func a()
}
@Spyable
protocol B: A {
func b()
} Given that protocol B extends protocol A, we can infer from its name that the corresponding spy for this protocol would be class BSpy: ASpy, B {
// Here we include only the methods from the B protocol
// because the methods from A are covered in `ASpy`
} |
@Matejkob thanks, I understand now, but yes, we cannot do multi inheritance this way |
That is way in my view the best options with current restrictions would be the 3th option. |
Ok, but what if there will be 2 parent protocols? We still cannot do multi inheritance here |
As for me, that is the problem, that cannot be solved without global code analyser, unfortunately. |
Oh, that you meant! I've got you! Yeah... I've forgotten about this limitation. In that case, probably there is no solution to that. |
This is a pretty interesting issue. I think any way we go with this, there's going to have to be a documentation component of the macro's limitations and our advised workarounds in these situations. Approach 2 It's syntactically simple and more automated, but as mentioned, it doesn't handle custom protocols well. If we go with an approach where we grab the conformed protocol and suffix "Spy", that'd lead to trying to inherit from a nonexistent @Spyable
protocol A: Equatable { func a() }
@Spyable
protocol B: A { func b() }
// Generated:
class ASpy: EquatableSpy, A {
func a() {}
}
class BSpy: ASpy, B {
func b() {}
} Our documented workaround could be to suggest creating
This is definitely a concern, but while it could be easy to forget to annotate a parent protocol with Approach 3 This requires more work from the user via the parameters, but it has the same issues where a Spy inheritance could be forgotten, by forgetting to use the @Spyable(inheritedTypes: "EquatableSpy")
protocol A: Equatable { func a() }
@Spyable(inheritedTypes: "ASpy")
protocol B: A { func b() }
// Generated:
class ASpy: EquatableSpy, A {
func a() {}
}
class BSpy: ASpy, B {
func b() {}
} With approach 3, applying @Spyable to protocol A would still require the manual creation of some class that conforms to Summary Given that both approaches have the same issues, and approach 2 keeps the To provide some guidance for users, we could generate a comment that links to documentation on the issue of conforming to things like Equatable, or just simply say something like, |
Is your feature request related to a problem? Please describe.
When using
@Spyable
macro on protocol that confirms another protocol, there is no additional methods of confirmed protocol, which leads to compilation error. Eg:Describe the solution you'd like
Would be great to have confirmed protocol methods in Spy class
The text was updated successfully, but these errors were encountered: