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: cannot infer T in an embedded field. #40814

Open
YoshikiShibata opened this issue Aug 15, 2020 · 3 comments
Open

cmd/go2go: cannot infer T in an embedded field. #40814

YoshikiShibata opened this issue Aug 15, 2020 · 3 comments

Comments

@YoshikiShibata
Copy link

@YoshikiShibata YoshikiShibata commented Aug 15, 2020

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)
@griesemer
Copy link
Contributor

@griesemer griesemer commented 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 griesemer modified the milestones: Unreleased, Go1.17 Feb 24, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented 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:

./prog.go2:19: y._X undefined (type instantiate୦୦_Y୦string has no field or method _X)

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).

@griesemer griesemer modified the milestones: Go1.17, Unreleased Apr 14, 2021
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 14, 2021

We are no longer fixing bugs in the go2go translator. In any case it has many problems with embedded fields.

@ianlancetaylor ianlancetaylor removed their assignment Apr 14, 2021
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
3 participants