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

Const has no type match #43158

Closed
mark4z opened this issue Dec 13, 2020 · 2 comments
Closed

Const has no type match #43158

mark4z opened this issue Dec 13, 2020 · 2 comments

Comments

@mark4z
Copy link

mark4z commented Dec 13, 2020

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

$ go version 1.15.5

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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mark4z/Library/Caches/go-build"
GOENV="/Users/mark4z/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mark4z/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mark4z/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/Cellar/go/1.15.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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/j0/gv3fglgj6zz_jpfcshjqzwrr0000gn/T/go-build066167980=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

u := uint32(1)
const b = 2
fmt.Print(u-b)

What did you expect to see?

error: invalid operation: u - b (mismatched types uint32 and int)

What did you see instead?

4294967295

It's a unpredictable behavior

@seankhliao
Copy link
Member

b is an untyped constant, see spec, blog post

@mdlayher
Copy link
Member

See above, and also see https://github.com/golang/go/wiki/Questions. Closing.

@golang golang locked and limited conversation to collaborators Dec 13, 2021
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