Skip to content

go/types: untyped int literal is identified as uint in go1.17 #47243

Closed
@ktye

Description

@ktye

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

$ go version
go version go1.17rc1 windows/amd64

Does this issue reproduce with the latest release?

the issue is different behaviour between go1.17 and go1.16

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\abc\AppData\Local\go-build
set GOENV=C:\Users\abc\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\dat\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:/dat/go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17rc1
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\k\i\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\msys64\tmp\go-build3488873506=/tmp/go-build -gno-record-gcc-switches

What did you do?

in go1.17 go/types identifies the literal 3 as uint, while go1.16 reports an untyped int kind.

func shift(x int32) int32 { return x << 3 }

see:
https://play.golang.org/p/WuuJ6PGlylQ

What did you expect to see?

Go1.16 (and the playground) shows:

Types and Values of each expression:
 4:14 | int32               | int32
 4:21 | int32               | int32
 4:36 | x                   | int32
 4:36 | x << 3              | int32
 4:41 | 3                   | untyped int = 3

What did you see instead?

Go1.17 shows:

Types and Values of each expression:
 4:14 | int32               | int32
 4:21 | int32               | int32
 4:36 | x                   | int32
 4:36 | x << 3              | int32
 4:41 | 3                   | uint = 3

Is this kind of change in go/types considered as a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions