Skip to content

Can not compile this: if err := T{}.F(); err != nil{} #37043

Closed
@DylanMeeus

Description

@DylanMeeus

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

$ go version 13

Does this issue reproduce with the latest release?

yes

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

Whatever is running on the playground - could reproduce under Debian with this env

"
GOCACHE="/home/dylan/.cache/go-build"
GOENV="/home/dylan/.config/go/env"
GOEXE=""
GOFLAGS=" -mod="
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/dylan/Development/Code/Go/"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/dylan/Development/Code/Dploy/dploy-main/go.mod"
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-build157748824=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/wLLYH3EVlGW

core code snippet:

if e := T{}.F(); e != nil { 
     // do something with e
}

What did you expect to see?

No compilation error, I expect this type if e := T{}.F(); e != nil{} to correctly resolve e to the result of F

What did you see instead?

Compilation error:

./prog.go:18:11: syntax error: e := T used as value

PS: I had a hard time naming this issue, feel free to rename

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions