Skip to content

Conversation

@bep
Copy link
Member

@bep bep commented Dec 31, 2025

Fixes #13418

@gemini-code-assist
Copy link

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

Copy link
Contributor

Copilot AI left a 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.Value parameters
  • Introduces a package-level variable to cache the reflect.Type of reflect.Value
  • Adds integration test to verify len and not work correctly with apply

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.

Comment on lines 93 to 99
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])
}
Copy link

Copilot AI Dec 31, 2025

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.

Copilot uses AI. Check for mistakes.

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.
Copy link

Copilot AI Dec 31, 2025

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".

Suggested change
// 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.
Copilot uses AI. Check for mistakes.
@bep bep merged commit 5c7fad2 into gohugoio:master Dec 31, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant