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: design corner cases when passing interface type arguments #39961

Open
tdakkota opened this issue Jun 30, 2020 · 4 comments
Open

cmd/go2go: design corner cases when passing interface type arguments #39961

tdakkota opened this issue Jun 30, 2020 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tdakkota
Copy link

tdakkota commented Jun 30, 2020

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

$ go version
go version devel +08b9fd164c Tue Jun 30 19:00:27 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)?

  • windows/amd64
  • Go2go playground

What did you do?

This code compiles https://go2goplay.golang.org/p/-5nF8t38Ebr - it's incorrect.

But this code does not compile https://go2goplay.golang.org/p/MdJl77uLB-g.

package main

import (
	"fmt"
)

type AwesomeMap(type V interface {
	type interface{}
}) map[string]V

type A interface {
	type interface{}
	Method()
}

func main() {
	var i AwesomeMap(A)
	fmt.Println(i)
}

What did you expect to see?

Compilation error in both cases.
type interface{} can't satisfy interface {Method();}

What did you see instead?

Successful compilation.

@ianlancetaylor
Copy link
Contributor

CC @griesemer

Sorry, I'm not sure what you are saying. You have two different examples. One compiles, one doesn't (because AwesomeMap is not defined). Under "what did you see instead" you listed both "successful compilation" and a type checking error.

Can you clarify the bug report? Thanks.

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

tdakkota commented Jul 1, 2020

Updated.

@griesemer
Copy link
Contributor

There's a couple of issues here. In

type AwesomeMap(type V interface {
	type interface{}
}) map[string]V

var _ AwesomeMap(interface {
	type interface{}
	Method()
})
...

it's not clear if we should permit a type argument that itself contains a type list (this is a design question). Also, should it be possible to pass a type argument that is an interface with Method to a type parameter that must be an interface (but doesn't have any methods)? I think that's another open design question. It's not clear to me that this should be legal or illegal for that matter.

@griesemer
Copy link
Contributor

The 2nd example behaves more sane (error reported), but I think the current design draft is unclear about exactly should happen in these cases.

@griesemer griesemer changed the title cmd/go2go: incorrect type checking for anonymous interfaces cmd/go2go: design corner cases when passing interface type arguments Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants