Closed
Description
Program https://go2goplay.golang.org/p/L5jQWGZvxDe cannot be compiled:
package main
import "fmt"
type X[type T] struct {
}
func (x X[T]) Hello() (T, bool) {
var v T
return v, true
}
type Y[type T] struct {
X[T]
}
func (y Y[T]) Foo() {
s, ok := y.Hello()
if ok {
fmt.Println(s)
}
}
func main() {
y := Y[string]{}
y.Foo()
}
type checking failed for main
prog.go2:19:11: type Y(T) of y does not match X(T) (cannot infer T)
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
griesemer commentedon Aug 28, 2020
This is a variation of the same problem that plagues #39758. It's not yet implemented and thus leads to odd errors.
griesemer commentedon Apr 14, 2021
This type-checks and compiles fine outside the playground (e.g.,
go tool compile -G=3 bug.go
). It also type-checks fine in the playground*. The new error:appears to be due to a bug in the go2go translator. Leaving for @ianlancetaylor to decide if he wants to address this.
*) This code was adjusted to match the currently supported syntax, and the generic types were unexported so that the compiler can handle it (as generic type export is not working yet).
ianlancetaylor commentedon Apr 14, 2021
We are no longer fixing bugs in the go2go translator. In any case it has many problems with embedded fields.
YoshikiShibata commentedon Nov 25, 2022
Now this is no issue.