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

cmd/compile: overflow in int -> string #11330

Closed
dvyukov opened this issue Jun 22, 2015 · 6 comments
Closed

cmd/compile: overflow in int -> string #11330

dvyukov opened this issue Jun 22, 2015 · 6 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jun 22, 2015

Gc rejects to compile the following program:

package a
var a = string(9223372036854775808)

saying:

overflow in int -> string

go/types compile it successfully.

Compilers must agree on whether it is a valid Go program or not.

on commit af81789

@griesemer
Copy link
Contributor

Given the spec as is, I believe this should compile w/o errors. The spec says:

http://tip.golang.org/ref/spec#Conversions

A constant value x can be converted to type T in any of these cases:
...
x is an integer constant and T is a string type. The same rule as for non-constant x applies in this case.

and:
http://tip.golang.org/ref/spec#Conversions_to_and_from_a_string_type

Converting a signed or unsigned integer value to a string type yields a string containing the UTF-8 representation of the integer. Values outside the range of valid Unicode code points are converted to "\uFFFD".

There's no mention of a compile-time (or even run-time) error. The integer should be converted into "\uFFFD".

@griesemer
Copy link
Contributor

Closed by mistake.

@griesemer griesemer reopened this Jun 22, 2015
@dvyukov
Copy link
Member Author

dvyukov commented Jun 22, 2015

Then this is a bug in gc, right?

@dvyukov dvyukov changed the title x/tools/go/types: overflow in int -> string cmd/compile: overflow in int -> string Jun 22, 2015
@dvyukov dvyukov assigned rsc and unassigned griesemer Jun 22, 2015
@griesemer
Copy link
Contributor

@dvyukov yes, I believe this is a gc compiler bug.

Note that we already return "\ufffd" for values < 0:

http://play.golang.org/p/1jrP-PnSdB

@rsc
Copy link
Contributor

rsc commented Jun 29, 2015

Too late for Go 1.5. The only possible visible effect of making changes to fix hypothetical bugs like this one is introducing real ones.

@griesemer
Copy link
Contributor

This was fixed via https://go-review.googlesource.com/#/c/21344/ (fix for #15039).

@golang golang locked and limited conversation to collaborators Aug 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants