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

cmd/compile: confusing compiler error when using if instead of for with range operator inside anonymous function #38624

Open
mzimmerman opened this issue Apr 23, 2020 · 2 comments
Assignees
Milestone

Comments

@mzimmerman
Copy link

@mzimmerman mzimmerman commented Apr 23, 2020

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

$ go version
go version go1.14.2 linux/amd64

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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mezimm00/.cache/go-build"
GOENV="/home/mezimm00/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mezimm00/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.14/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mezimm00/machine/src/createI2chart/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-build527871476=/tmp/go-build -gno-record-gcc-switches"

What did you do?

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

What did you expect to see?

syntax error: unexpected range, expecting expression

What did you see instead?

expression in go must be function call

When I typically see this error it's because I forgot the () on an anonymous function. In this case I didn't though. Instead, this error is reported when there was an error inside the anonymous function; that being using an if instead of the intended for with the range operator.

@andybons andybons changed the title Confusing compiler error when using if instead of for with range operator inside anonymous function cmd/compile: confusing compiler error when using if instead of for with range operator inside anonymous function Apr 23, 2020
@andybons andybons added this to the Unplanned milestone Apr 23, 2020
@andybons
Copy link
Member

@andybons andybons commented Apr 23, 2020

@griesemer
Copy link
Contributor

@griesemer griesemer commented Apr 23, 2020

Thanks for the report. This looks like a problem with the parser recovering gracefully in the presence of the syntax error (use of range inside an if).

@griesemer griesemer self-assigned this Apr 23, 2020
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
You can’t perform that action at this time.