Skip to content
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

text/template: cannot index with literal integer from map[int32]string #20439

Closed
bupjae opened this issue May 20, 2017 · 6 comments
Closed

text/template: cannot index with literal integer from map[int32]string #20439

bupjae opened this issue May 20, 2017 · 6 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bupjae
Copy link

bupjae commented May 20, 2017

What version of Go are you using (go version)?

go1.8

What operating system and processor architecture are you using (go env)?

(go playground)

What did you do?

https://play.golang.org/p/dMKNy4pTnb

What did you expect to see?

[ ok] Element 0 is zero
[ ok] Element 0 is zero
[ ok] Element 0 is zero

What did you see instead?

[ ok] Element 0 is zero
[ ok] Element 0 is zero
[err] template: :1:15: executing "" at <index . 0>: error calling index: value has type int; should be int32 

I think "untyped" integer in template should become not only "int", but also "int32", "int64", ......

@bupjae bupjae changed the title text/template: cannot index from map[int32]string text/template: cannot index with literal integer from map[int32]string May 20, 2017
@odeke-em
Copy link
Member

/cc @robpike @rsc

  • text/template documents this
    as predefined global function
index
	Returns the result of indexing its first argument by the
	following arguments. Thus "index x 1 2 3" is, in Go syntax,
	x[1][2][3]. Each indexed item must be a map, slice, or array.

screen shot 2017-05-20 at 11 49 33 am

must be a map so no restriction on the typing, IMO should be fixed as per this bug report.

  • Also an additional note is that "html/template" has the same functionality but predefined global functions are not documented for "html/template" as per https://play.golang.org/p/Gf9Ez_QEyY.

@odeke-em odeke-em added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 22, 2017
@rsc
Copy link
Contributor

rsc commented May 22, 2017

This is just a bug. Constants are supposed to be ideal-like and should convert to int32 here.

@bradfitz bradfitz added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels May 22, 2017
@bradfitz bradfitz added this to the Go1.10 milestone May 22, 2017
@bradfitz
Copy link
Contributor

Or, if somebody has an easy fix this week, Go 1.9 is fine too.

@gopherbot
Copy link

CL https://golang.org/cl/43850 mentions this issue.

@odeke-em
Copy link
Member

Cool, thanks for the information, for starters, I've mailed https://go-review.googlesource.com/43850.

@odeke-em
Copy link
Member

I mailed a CL for Go1.9 on that day as per #20439 (comment). Should we instead mark it as for Go1.10?

@odeke-em odeke-em self-assigned this Aug 10, 2017
@golang golang locked and limited conversation to collaborators Aug 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants