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

Closed
b-kaiser opened this issue Nov 26, 2021 · 6 comments
Closed

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

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

Comments

@b-kaiser
Copy link

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 seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Documentation labels Nov 26, 2021
@seankhliao
Copy link
Member

cc @griesemer

@griesemer griesemer self-assigned this Nov 26, 2021
@griesemer griesemer removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 26, 2021
@griesemer
Copy link
Contributor

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

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

No, please leave it open. Thanks.

@ianlancetaylor
Copy link
Contributor

@griesemer This is in the 1.18 milestone; time to move to 1.19? Thanks.

@griesemer griesemer modified the milestones: Go1.18, Go1.19 Jan 29, 2022
@griesemer
Copy link
Contributor

This is now addressed in the latest spec: The section on numeric types explicitly introduces the terms.

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

5 participants