feat(injector): Support generic join point types#628
Merged
Conversation
kakkoyun
reviewed
May 16, 2025
kakkoyun
left a comment
Member
There was a problem hiding this comment.
Looking good @colinodell
First of all, thanks a lot for the contribution.
Could you please maybe add some tests? Or extend the existing test?
Contributor
Author
|
Sure! It seemed like there were no unit tests for |
This file contains hidden or 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
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 allows Orchestrion's
functionjoin point to correctly match methods on receivers that are instantiations of generic types (e.g.,*MyType[T]).Problem
Currently, when a method receiver is a generic type like
*MyType[T], the Go AST structure is more complex than a simple identifier. Forgithub.com/dave/dstnodes, it looks something like this:(For multiple type parameters like
MyType[T, U], it would be*dst.IndexListExprwith multipleIndices).However, the existing
join.TypeName.Matchesmethod lacked the necessary cases to handle the*dst.IndexExpror*dst.IndexListExpr. It would therefore fail to match any user-specified base type likeMyTypeto method receivers likeMyType[T], meaning that generic types could not be targeted.Solution
I've updated the
join.TypeName.Matchesmethod to include cases for*dst.IndexExprand*dst.IndexListExpr. When these nodes are encountered (representing an instantiated generic type), the matching logic now correctly compares the user-provided type against the base type of the generic (e.g.,MyType).