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/go2go: 2-valued values cannot be assigned to two variables. #40815

Closed
YoshikiShibata opened this issue Aug 15, 2020 · 3 comments
Closed

cmd/go2go: 2-valued values cannot be assigned to two variables. #40815

YoshikiShibata opened this issue Aug 15, 2020 · 3 comments

Comments

@YoshikiShibata
Copy link

2-valued values cannot be assigned to two variables: https://go2goplay.golang.org/p/rKe_LDnHgM_m

package main

type Predicate[type T] func(t T) bool

type prevStream[type T] struct {
	req  chan struct{}
	data chan T
}

func (ps prevStream[T]) prevData() (T, bool) {
	ps.req <- struct{}{}
	d, ok := <-ps.data
	return d, ok
}

func (ps prevStream[T]) closePrev() {
	close(ps.req)
}

type genericStream[type T] struct {
	prevStream[T]
	nextReq  chan struct{}
	nextData chan T
}

func (gs *genericStream[T]) filter(predicate Predicate[T]) {
	for range gs.nextReq {
		data, ok := <-gs.prevStream.prevData()
		if !ok {
			close(gs.nextData)
			gs.prevStream.closePrev()
			return
		}

		for !predicate(data) {
			data, ok = <-gs. prevStream.prevData()
			if !ok {
				close(gs.nextData)
				gs.prevStream.closePrev()
				return
			}
		}
		gs.nextData <- data
	}
}

func main() {
}
type checking failed for main
prog.go2:28:17: 2-valued gs.prevStream.prevData() (value of type (T, bool)) where single value is expected
prog.go2:36:17: 2-valued gs.prevStream.prevData() (value of type (T, bool)) where single value is expected
@zephyrtronium
Copy link
Contributor

You're using the receive operator on the result of gs.prevStream.prevData(), which is two values, not a channel. The receive operator cannot be used on two values, hence the type check failure.

@ianlancetaylor
Copy link
Contributor

Agreed. This is not a bug.

@YoshikiShibata
Copy link
Author

Oops. Sorry for bothering.

@golang golang locked and limited conversation to collaborators Aug 17, 2021
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

4 participants