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: better error message for ambiguous parse #70971

Closed
kyletannousdev opened this issue Dec 23, 2024 · 1 comment
Closed

cmd/compile: better error message for ambiguous parse #70971

kyletannousdev opened this issue Dec 23, 2024 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@kyletannousdev
Copy link

Go version

go version 1.23

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/smu/.cache/go-build'
GOENV='/home/smu/.config/go/env'
GOEXE=''
GOEXPERIMENT='fieldtrack,boringcrypto'
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/smu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/smu/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/google-golang'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/google-golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23 [redacted] X:fieldtrack,boringcrypto'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/smu/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1689118444=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I expected

if mErr := &MyError{}; errors.As(err1, &mErr) {
...
}

to be parse correctly. See https://go.dev/play/p/XHkampOkowJ for a reproduction case.

Actual result of that playground snippet was:

./prog.go:23:10: syntax error: cannot use mErr := &MyError as value
./prog.go:26:1: syntax error: non-declaration statement outside function body

Changing the line

if mErr := &MyError{}; errors.As(err1, &mErr) {

into

if mErr := &(MyError{}); errors.As(err1, &mErr) {

makes the code work, but I would expect the first variant to work just as well.

What did you see happen?

./prog.go:23:10: syntax error: cannot use mErr := &MyError as value
./prog.go:26:1: syntax error: non-declaration statement outside function body

What did you expect to see?

A compiled program

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

3 participants