Hugo

Reflecting upon where

My misadventures in debugging an odd issue with a where clause…

I submitted PR-5570 after trying to understand why we’re unable to use IsDescendant with where. With the PR, the following returns a more useful, although curious, error:

{{ range where .Pages "IsDescendant" . }}

error calling where: IsDescendant is a method of type *hugolib.Page but requires more than 1 parameter

That’s odd since IsDescendant is defined as:

func (p *Page) IsDescendant(other interface{}) (bool, error) {

With some digging, I found that the method type returned by the reflect package has a NumIn of 2.

Step #1 in Go Debugging: print the thing.

fmt.Printf("%s\n", mt)
// func(*hugolib.Page, interface {}) (bool, error)

So, internally, Go sends the receiver as an argument in the method call. That’s very interesting.

I’m not sure how to solve this issue in Hugo yet. I took a quick stab at a fix, but it didn’t pan out. So, I thought I would share my findings in case someone wanted to beat me to a resolution.