-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
chore: support decorating multi-function interfaces #26323
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
Merged
Merged
+109
−37
Conversation
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
Collaborator
|
Is there anything else that needs to be done here? |
Contributor
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.
Hey - I've found 1 issue, and left some high level feedback:
- In
main, when buildingdynamicTypes,strings.SplitN(v, ",", 2)is assumed to always return a slice of length 2; consider checking the length before indexingsplit[1]to avoid panics on malformed-targuments. parseFunctionssilently drops a trailing token if the interface string has an odd number of comma-separated parts (e.g. missing a signature); consider validating the input and failing fast or logging an error when the function/signature pairs are incomplete.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `main`, when building `dynamicTypes`, `strings.SplitN(v, ",", 2)` is assumed to always return a slice of length 2; consider checking the length before indexing `split[1]` to avoid panics on malformed `-t` arguments.
- `parseFunctions` silently drops a trailing token if the interface string has an odd number of comma-separated parts (e.g. missing a signature); consider validating the input and failing fast or logging an error when the function/signature pairs are incomplete.
## Individual Comments
### Comment 1
<location> `cmd/decorate/decorate.go:310-314` </location>
<code_context>
+ return res
+}
+
+func parseFunctions(iface string) []function {
+ parts := splitTopLevel(iface)
+
+ var res []function
+ for i := 0; i+1 < len(parts); i += 2 {
+ res = append(res, function{
+ function: parts[i],
</code_context>
<issue_to_address>
**issue:** parseFunctions silently drops a trailing unmatched token when the number of parts is odd
Because the loop uses `i+1 < len(parts)`, an odd number of elements from `splitTopLevel` causes the final element to be silently ignored. For malformed input like `Multi1,func() error,Multi2`, the trailing `"Multi2"` is dropped without any warning. Consider detecting `len(parts)%2 != 0` and either returning an error or otherwise surfacing this case so misconfiguration doesn’t lead to partially generated decorators.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
@Maschga the parsing logic already exists but it's not used in the generator template. So more work to be done, feel free to take a stab.