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

spec: conversions doc content is somewhat ambiguous #41971

Closed
aniaan opened this issue Oct 14, 2020 · 3 comments
Closed

spec: conversions doc content is somewhat ambiguous #41971

aniaan opened this issue Oct 14, 2020 · 3 comments
Labels
Documentation FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@aniaan
Copy link

aniaan commented Oct 14, 2020

What version of Go are you using (go version)?

$ go version
go version go1.15 linux/amd64


Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/beanan/Library/Caches/go-build"
GOENV="/Users/beanan/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/beanan/.asdf/installs/golang/1.15.2/packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/beanan/.asdf/installs/golang/1.15.2/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/beanan/.asdf/installs/golang/1.15.2/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/beanan/.asdf/installs/golang/1.15.2/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8z/c8c8dkx53m936yg490kdw5480000gn/T/go-build354871818=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

What did you expect to see?

What did you see instead?

The full description is as follows:

A non-constant value x can be converted to type T in any of these cases:

x is assignable to T.
ignoring struct tags (see below), x's type and T have identical underlying types.
ignoring struct tags (see below), x's type and T are pointer types that are not defined types, and their pointer base types have identical underlying types.
x's type and T are both integer or floating point types.
x's type and T are both complex types.
x is an integer or a slice of bytes or runes and T is a string type.
x is a string and T is a slice of bytes or runes.

When I was looking at the type conversion document, I found a sentence of copywriting was somewhat ambiguous,

"x is an integer or a slice of bytes or runes and T is a string type"
link: https://golang.google.cn/ref/spec#Conversions

The type here should be the underlying type of that type. I looked at the source code and compared the underlying type used in the isInteger function in the source code.

// "x is an integer or a slice of bytes or runes and T is a string type"
if (isInteger(V) || isBytesOrRunes(Vu)) && isString(T) {
	return true
}

func isInteger(typ Type) bool {
        t, ok := typ.Underlying().(*Basic)
	return ok && t.info&IsInteger != 0
}

In this document, all the places where the underlying type is used are specifically explained, but this sentence is not explained, I am a little confused because it is omitted here or because it has other meanings

@rsc
Copy link
Contributor

rsc commented Oct 14, 2020

The text is accurate as written. If you have

type Ti int
type Ts string

Then both "int" and "Ti" can be described as "an integer type" and similarly both "string" and "Ts" can be described as "a string type". (Not "the type string" but "a string type").

There is no need to introduce discussion of underlying type here in this part of the text. If anything I think that would be more confusing.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 14, 2020
@dotaheor
Copy link

gc and gccgo do interpret this rule differently: #23536

@dmitshur dmitshur changed the title doc: Conversions doc content is somewhat ambiguous spec: conversions doc content is somewhat ambiguous Oct 14, 2020
@ianlancetaylor
Copy link
Contributor

Thanks, I'm going to close this as a dup of #23536 since I think that covers all the same issues. Please comment if you disagree.

@golang golang locked and limited conversation to collaborators Oct 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants