Skip to content

Conversation

@cce
Copy link
Contributor

@cce cce commented May 20, 2021

Summary

Go 1.15 introduced a new check in the vet tool for string(int) conversion that is enabled by default when running go test, causing the TestWebsocketNetworkCancel test to fail. This replaces int-to-string conversion with the first recommended solution from the Go 1.15 release notes:

Experience with Go has shown that many conversions of this form erroneously assume that string(x) evaluates to the string representation of the integer x. It actually evaluates to a string containing the UTF-8 encoding of the value of x. ...

Code that is using string(x) correctly can be rewritten to string(rune(x)). Or, in some cases, calling utf8.EncodeRune(buf, x) with a suitable byte slice buf may be the right solution. Other code should most likely use strconv.Itoa or fmt.Sprint.

Test Plan

This fixes a unit test.

@CLAassistant
Copy link

CLAassistant commented May 20, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@tsachiherman tsachiherman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@tsachiherman tsachiherman merged commit 364db6d into algorand:master May 21, 2021
@cce cce deleted the fix-1.15-string-int-conversion branch May 21, 2021 14:11
tsachiherman pushed a commit to tsachiherman/go-algorand that referenced this pull request Jul 7, 2021
…on go >=1.15 (algorand#2170)

## Summary

Go 1.15 introduced a new check in the vet tool for `string(int)` conversion that is enabled by default when running `go test`, causing the TestWebsocketNetworkCancel test to fail. This replaces int-to-string conversion with the first recommended solution from the [Go 1.15 release notes](https://golang.org/doc/go1.15#vet):

> Experience with Go has shown that many conversions of this form erroneously assume that `string(x)` evaluates to the string representation of the integer x. It actually evaluates to a string containing the UTF-8 encoding of the value of x. ...
>
> Code that is using `string(x)` correctly can be rewritten to `string(rune(x))`. Or, in some cases, calling `utf8.EncodeRune(buf, x)` with a suitable byte slice `buf` may be the right solution. Other code should most likely use `strconv.Itoa` or `fmt.Sprint`.

## Test Plan

This fixes a unit test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants