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: integer and floating point types are not explicitly defined #49804

Open
b-kaiser opened this issue Nov 26, 2021 · 4 comments
Open

spec: integer and floating point types are not explicitly defined #49804

b-kaiser opened this issue Nov 26, 2021 · 4 comments
Assignees
Milestone

Comments

@b-kaiser
Copy link

@b-kaiser b-kaiser commented Nov 26, 2021

In go1.17_spec.html lines 866 to 890 the notion of (predeclared) numerical types is defined by defining each of these (predeclared) numerical types individually. However, integer types and floating-point types are not defined.

<p>
A <i>numeric type</i> represents sets of integer or floating-point values.
The predeclared architecture-independent numeric types are: 
</p>

<pre class="grammar">
uint8       the set of all unsigned  8-bit integers (0 to 255)
uint16      the set of all unsigned 16-bit integers (0 to 65535)
uint32      the set of all unsigned 32-bit integers (0 to 4294967295)
uint64      the set of all unsigned 64-bit integers (0 to 18446744073709551615)

int8        the set of all signed  8-bit integers (-128 to 127)
int16       the set of all signed 16-bit integers (-32768 to 32767)
int32       the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64       the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

float32     the set of all IEEE-754 32-bit floating-point numbers
float64     the set of all IEEE-754 64-bit floating-point numbers

complex64   the set of all complex numbers with float32 real and imaginary parts
complex128  the set of all complex numbers with float64 real and imaginary parts

byte        alias for uint8
rune        alias for int32
</pre>

Nevertheless, throughout the specification the notion of an integer type is used in the specification of the language (e.g. in lines 2530, 3128, 3600, 4234, 4375, 5939, 6731, 6793 and 6816) and similarly, the notion of a floating-point type is used in the specification of the language, too ( e.g. in lines 1686, 3819, 4245, 6084 and (in an example) 6121).

Even though for experienced programmers it is clear from context what integer types and floating point types are, after numerical types have been defined, there is actually some ambiguity. Whether for example in the language specification indexing by integer types includes includes indexing by int32, too, or unsigned integer types. Additionally, the officially recommended debugger dlv does not recognize indexing by uint32 when using the command print (which likely is a bug in dlv, though), whereas the official compiler as of version go1.16.2 and the compiler of the go playground do (see example below).

If writing safe code is of concern, then I even prefer to assume, that indexing by non-int types is a feature of the compiler and not the language itself.

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

$ go version go1.16.2 linux/amd64

The problem is in the The Go Programming Language Specification Version of Jul 26, 2021.

Does this issue reproduce with the latest release?

Yes. (Also see example below.)

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="private"
GOENV="private"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="private"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="private"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.16"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.16/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="private"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1557285062=/tmp/go-build -gno-record-gcc-switches"

Example for indexing with several different non-int types:

See https://go.dev/play/p/QpKQtOK4F-j

What did you expect to see?

Unclear, because the problem is the ambiguity of the go spec.

@seankhliao seankhliao changed the title Go Spec: integer and floating point types are not explicitely defined spec: integer and floating point types are not explicitely defined Nov 26, 2021
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Nov 26, 2021

@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 26, 2021

Thanks for the issue. This is a known concern and on the list of things to be addressed for the Go 1.18 spec because we need to expand the terminology to incorporate type parameters that act as "integers" or "floats".

@griesemer griesemer added this to the Go1.18 milestone Nov 26, 2021
@b-kaiser
Copy link
Author

@b-kaiser b-kaiser commented Nov 27, 2021

Ok, thank you. Shall I close?

@robpike robpike changed the title spec: integer and floating point types are not explicitely defined spec: integer and floating point types are not explicitly defined Nov 27, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 28, 2021

No, please leave it open. Thanks.

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
3 participants