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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tdakkota
Copy link

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

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 Importable୦ int

where Nat is not defined.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 29, 2020
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Aug 29, 2020
@ianlancetaylor
Copy link
Contributor

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

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

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

Fixed on dev.go2go branch.

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>
@golang golang locked and limited conversation to collaborators Aug 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants