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: should eq permit comparison of signed and unsigned integers #7489

Closed
robpike opened this issue Mar 7, 2014 · 6 comments
Closed
Milestone

Comments

@robpike
Copy link
Contributor

@robpike robpike commented Mar 7, 2014

Consider this example: 

// http://play.golang.org/p/wkyxTmGM0F

import "os"
import "text/template"

func main() {
    template.Must(template.New("test").Parse(`{{printf "%T %T" (index . 0) 'a'}}`)).Execute(os.Stdout, "abc")
}


It prints uint8 int, which prevents using eq from comparing a byte to a rune constant,
so one can't do
    {{eq (index . 0) 'a'}}
Perhaps comparisons between signed and unsigned integer values should be OK if the sign
is positive, or maybe even always.
@rsc
Copy link
Contributor

@rsc rsc commented Apr 3, 2014

Comment 1:

template already knows how to promote constants for ordinary calls.
Can it know about "eq" needing compatible types if a constant is used?
@rsc
Copy link
Contributor

@rsc rsc commented May 9, 2014

Comment 2:

Too late for 1.3.

Labels changed: added release-go1.4, removed release-go1.3maybe.

@adg
Copy link
Contributor

@adg adg commented Aug 20, 2014

Comment 3:

Why does "(index . 0)" on a string produce a uint8?
@rsc
Copy link
Contributor

@rsc rsc commented Sep 18, 2014

Comment 4:

adg, what should it produce? That's what a string is, a bunch of uint8s.
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 19, 2014

Comment 5:

CL https://golang.org/cl/149780043 mentions this issue.
@robpike
Copy link
Contributor Author

@robpike robpike commented Sep 22, 2014

Comment 6:

This issue was closed by revision db56d4d.

Status changed to Fixed.

@robpike robpike added fixed labels Sep 22, 2014
@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
Previously, signed and unsigned integers could not be compared, but
this has problems with things like comparing 'x' with a byte in a string.
Since signed and unsigned integers have a well-defined ordering,
even though their types are different, and since we already allow
comparison regardless of the size of the integers, why not allow it
regardless of the sign?

Integers only, a fine place to draw the line.

Fixes golang#7489.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/149780043
wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
Previously, signed and unsigned integers could not be compared, but
this has problems with things like comparing 'x' with a byte in a string.
Since signed and unsigned integers have a well-defined ordering,
even though their types are different, and since we already allow
comparison regardless of the size of the integers, why not allow it
regardless of the sign?

Integers only, a fine place to draw the line.

Fixes golang#7489.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/149780043
wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
Previously, signed and unsigned integers could not be compared, but
this has problems with things like comparing 'x' with a byte in a string.
Since signed and unsigned integers have a well-defined ordering,
even though their types are different, and since we already allow
comparison regardless of the size of the integers, why not allow it
regardless of the sign?

Integers only, a fine place to draw the line.

Fixes golang#7489.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/149780043
This issue was closed.
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
4 participants
You can’t perform that action at this time.