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
Assignees
Milestone

Comments

@bupjae
Copy link

@bupjae 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

@odeke-em odeke-em commented May 20, 2017

/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.
@rsc
Copy link
Contributor

@rsc 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 and removed NeedsDecision labels May 22, 2017
@bradfitz bradfitz added this to the Go1.10 milestone May 22, 2017
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented May 22, 2017

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

@gopherbot
Copy link

@gopherbot gopherbot commented May 22, 2017

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

@odeke-em
Copy link
Member

@odeke-em odeke-em commented May 22, 2017

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

@odeke-em
Copy link
Member

@odeke-em odeke-em commented Jun 16, 2017

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
@gopherbot gopherbot closed this in 590c5b0 Aug 12, 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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.