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

go/parser: cannot parse channel of channel with receive direction #48354

Closed
vladimiroff opened this issue Sep 13, 2021 · 1 comment
Closed

go/parser: cannot parse channel of channel with receive direction #48354

vladimiroff opened this issue Sep 13, 2021 · 1 comment

Comments

@vladimiroff
Copy link

vladimiroff commented Sep 13, 2021

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

$ go version
go version go1.17.1 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/kiril/.cache/go-build"
GOENV="/home/kiril/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4024821342=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Tried to make channel of channels with receive direction: https://play.golang.org/p/1dR3qhjMF90

Simplified example, where a single click on "Format" highlights the issue: https://play.golang.org/p/M8Yn3NAP6V5
At first I thought this is a bug in gofmt, changing the semantic of my code.

What did you expect to see?

Expected to be able to send channels with receive-only direction through that channel.

What did you see instead?

The "root" channel is made with send-only direction instead, during make, thus making it useless:

./prog.go:9:9: invalid operation: <-chch (receive from send-only type chan<- chan int)

Workaround

Adding parentheses around the inner channel solves the issue:

	chch := make(chan (<-chan int))
@ALTree
Copy link
Member

ALTree commented Sep 13, 2021

This is working as expected, from the Language specification:

The <- operator associates with the leftmost chan possible:

chan<- chan int // same as chan<- (chan int)

as you noted, you need parentheses to get the direction to be associated to the right channel.

@ALTree ALTree closed this as completed Sep 13, 2021
@golang golang locked and limited conversation to collaborators Sep 13, 2022
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

3 participants