Skip to content

text/template: calling a *T method on elements of []T: works with range, not with index #14916

@bengalin

Description

@bengalin
  1. What version of Go are you using (go version)?
    1.6
  2. What operating system and processor architecture are you using (go env)?
    linux/amd64
  3. What did you do?
    http://play.golang.org/p/5EinJM-QLi
    Consider a template where dot is set to a slice of (non-pointer) values.
    If I {{range}} on dot, I can call pointer-receiver methods on each element. However, if I {{index}} on dot, then pointer-receiver methods cause the template execution to fail with a "PointerReceiver is not a field of struct type main.someStruct" error.
  4. What did you expect to see?
    Pointer-receiver method works on {{index}}ed elements just as it does on {{range}}d ones.
    It has been suggested to me that might be "a bug in the template package: for method calls on slice elements, it should probably be using v.Index(i).Addr().Call([...]) rather than v.Index(i).Call([...])"
  5. What did you see instead?
    See error above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions