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: usage of interface with type list not as type constraint shouldn't be allowed #41124

Closed
tdakkota opened this issue Aug 29, 2020 · 5 comments
Assignees
Milestone

Comments

@tdakkota
Copy link

@tdakkota tdakkota commented Aug 29, 2020

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

$ go version
go version devel +ea8318cad7 Sat Aug 29 01:02:37 2020 +0000 windows/amd64

Does this issue reproduce with the latest release?

n/a

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

  • go2go playground
  • windows/amd64

What did you do?

https://go2goplay.golang.org/p/fD4PjTJLgdz

What did you expect to see?

Successful compilation or better error message.

What did you see instead?

# play
./prog.go2:8: undefined: Nat
@tdakkota
Copy link
Author

@tdakkota tdakkota commented Aug 29, 2020

Seems like bug in the translation tool

type Nat interface {
	type Zero, Succ
}

type Zero struct{}
type Succ struct{ Nat }

becomes

type Zero struct{}
type Succ struct{ Nat }

type Importableint

where Nat is not defined.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 29, 2020

This shouldn't pass the type checker. You aren't allowed to embed an interface with a type list into a struct. An interface with a type list can only be used as a type constraint, not as a general type.

So, yes, the translation tool mishandles it, but this code shouldn't get to the translation tool at all.

@tdakkota
Copy link
Author

@tdakkota tdakkota commented Aug 30, 2020

var _ map[A]struct{}
var _ map[int]A
var _ []A
var _ chan A

https://go2goplay.golang.org/p/TKaDmb6jrop
passes the type checker too

@tdakkota tdakkota changed the title cmd/go2go: confusing error when type list constraint contains itself cmd/go2go: usage of interface with type list not as type constraint shouldn't be allowed Aug 30, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Aug 31, 2020

Change https://golang.org/cl/251718 mentions this issue: [dev.go2go] go/types: interfaces with type lists cannot be embedded in structs

@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 31, 2020

Fixed on dev.go2go branch.

@griesemer griesemer closed this Aug 31, 2020
gopherbot pushed a commit that referenced this issue Aug 31, 2020
…constraints

Check that such constraint interfaces don't appear in:
- composite types
- type and function instantiations
- assertions
- type switches

Streamlined respective error messages. Added lots of tests.

Fixes #41124.

Change-Id: Ie04a95ab056b40561484f04ed6e843ca371e1d41
Reviewed-on: https://go-review.googlesource.com/c/go/+/251718
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
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
4 participants
You can’t perform that action at this time.