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

Closed
YoshikiShibata opened this issue Aug 15, 2020 · 4 comments
Closed

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

YoshikiShibata opened this issue Aug 15, 2020 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@YoshikiShibata
Copy link

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)
@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 16, 2020
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Aug 16, 2020
@griesemer
Copy link
Contributor

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

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

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
@YoshikiShibata
Copy link
Author

Now this is no issue.

@golang golang locked and limited conversation to collaborators Nov 25, 2023
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