-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
tpl/collections: Fix apply to work with built-in funcs like len #14330
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
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
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.
Pull request overview
This PR fixes issue #13418 by enabling the apply function to work with Go's built-in template functions like len and not, which expect reflect.Value arguments. The fix adds logic to automatically wrap arguments in reflect.Value when the target function requires it.
- Adds automatic argument wrapping for built-in functions that expect
reflect.Valueparameters - Introduces a package-level variable to cache the
reflect.Typeofreflect.Value - Adds integration test to verify
lenandnotwork correctly withapply
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tpl/collections/apply.go | Adds typeOfReflectValue variable and wrapping logic in applyFnToThis to convert arguments to reflect.Value when required by built-in template functions |
| tpl/collections/collections_integration_test.go | Adds TestApplyBuiltInIssue13418 test to verify apply works with built-in functions len and not |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for i := range num { | ||
| // AssignableTo reports whether xt is assignable to type targ. | ||
| // Go's built-in template funcs (e.g. len) uses reflect.Value as argument type. | ||
| if fn.Type().In(i) == typeOfReflectValue && n[i].Type() != typeOfReflectValue { | ||
| n[i] = reflect.ValueOf(n[i]) | ||
| } |
Copilot
AI
Dec 31, 2025
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.
The wrapping logic only processes non-variadic parameters (iterating up to num). For variadic built-in functions like index or slice that take ...reflect.Value parameters, the variadic arguments won't be wrapped. Consider extending the loop to also wrap variadic parameters by checking if fn.Type().IsVariadic() and then wrapping arguments at indices >= num using fn.Type().In(num) as the expected type.
tpl/collections/apply.go
Outdated
|
|
||
| for i := range num { | ||
| // AssignableTo reports whether xt is assignable to type targ. | ||
| // Go's built-in template funcs (e.g. len) uses reflect.Value as argument type. |
Copilot
AI
Dec 31, 2025
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.
Grammar issue: "funcs" is plural, so the verb should be "use" instead of "uses".
| // Go's built-in template funcs (e.g. len) uses reflect.Value as argument type. | |
| // Go's built-in template funcs (e.g. len) use reflect.Value as argument type. |
Fixes #13418