golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.68k stars 17.49k forks source link

cmd/go2go: type parameters can omit any constraint #41042

Closed changkun closed 4 years ago

changkun commented 4 years ago

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

$ go version
go version devel +1964d56295 Wed Aug 26 01:59:01 2020 +0000 darwin/amd64

What did you do?

According to the commit message of https://github.com/golang/go/commit/1964d562957d94ebc105e09eabee12a5eec9c0fd:

all type parameters must have a constraint, can be "any"

However, given the following example:

// p.go2
package p

type I [T] interface {
    M() T
}

What did you expect to see?

Throw missing constraint error, e.g.

$ go tool go2go translate p.go2
p.go2:3:10: expected type constraint, found ']'

What did you see instead?

$ go tool go2go translate p.go2

Nothing thrown.

ianlancetaylor commented 4 years ago

The experimental translation tool accepts a range of syntaxes. It does not strictly enforce the rules required by the design draft.

changkun commented 4 years ago

@ianlancetaylor But where to find a document for all possibilities without knowing the implementation details? How can one classify bugs apart from expected behaviors?

ianlancetaylor commented 4 years ago

go2go is an experimental tool, and the main purpose of the tool is to see if the generics design draft provides the semantics that people need and want. The syntax is not the point of the tool. Report bugs where the behavior is not what you expect, or where you can't do what you want. Bugs about syntactic details are less interesting, because the syntax is much easier to change than the semantics.

That said, we will soon be updating the dev.go2go branch to default to only permitting the syntax described in the design draft.

Thanks.