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: add break and continue support #20531

Open
bep opened this issue May 30, 2017 · 10 comments
Open

text/template: add break and continue support #20531

bep opened this issue May 30, 2017 · 10 comments

Comments

@bep
Copy link
Contributor

@bep bep commented May 30, 2017

This is a repost of #20523 with, hopefully, a more clear description.

Go templates currently do not support the break nor the continue keyword -- which surprises people trying a construct similar to the one below.

{{ range $i, $e := .SomeSlice }}
  {{ if gt $i 2 }}
    {{ break }}
  {{ end }}
  {{ $e }}
{{ end }}

/cc @igramnet

@odeke-em odeke-em changed the title text/template: Add break and continue support proposal: text/template: add break and continue support May 31, 2017
@gopherbot gopherbot added this to the Proposal milestone May 31, 2017
@gopherbot gopherbot added the Proposal label May 31, 2017
@odeke-em

This comment has been minimized.

Copy link
Member

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

/cc @rsc @robpike and other text/template folks.

@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Jun 5, 2017

It does seem a little reasonable. I wouldn't want labels (or goto), though. Thoughts, @robpike?

@robpike

This comment has been minimized.

Copy link
Contributor

@robpike robpike commented Jun 5, 2017

It does seem reasonable but low priority.

@rsc rsc changed the title proposal: text/template: add break and continue support text/template: add break and continue support Jun 12, 2017
@rsc rsc modified the milestones: Go1.10, Proposal Jun 12, 2017
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Jun 12, 2017

CLs welcome for Go 1.10. Thanks.

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Sep 27, 2017

Change https://golang.org/cl/66410 mentions this issue: text/template: add break, continue actions in ranges

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Feb 5, 2018

Change https://golang.org/cl/92155 mentions this issue: text/template: revert CL 66410 "add break, continue actions in ranges"

@robpike robpike reopened this Feb 6, 2018
@gopherbot gopherbot closed this in fd7331a Feb 6, 2018
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 6, 2018

The patch was rolled back, so reopening.

@ianlancetaylor ianlancetaylor reopened this Feb 6, 2018
@ALTree ALTree modified the milestones: Go1.10, Go1.11 Feb 7, 2018
@jimmyfrasche

This comment has been minimized.

Copy link
Member

@jimmyfrasche jimmyfrasche commented Feb 15, 2018

This seems like an easy way to create goroutine leaks that weren't possible before since range can iterate over a channel.

@robpike

This comment has been minimized.

Copy link
Contributor

@robpike robpike commented Feb 15, 2018

@jimmyfrasche There are zillions of ways to create goroutine leaks. Adding one more doesn't seem to be that much of a change to the world.

@jimmyfrasche

This comment has been minimized.

Copy link
Member

@jimmyfrasche jimmyfrasche commented Feb 16, 2018

@robpike Certainly true. I originally thought that this is different as, if the templates are user provided, it's a way for the provided template to cause the leak, but then I realized that the same goroutine leak could be caused by the template simply choosing to not range over the channel at all. Either way, it's up to the program running the template to ensure all chans are drained after execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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