Skip to content

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

Closed
@YoshikiShibata

Description

@YoshikiShibata

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)

Activity

added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Aug 16, 2020
added this to the Unreleased milestone on Aug 16, 2020
griesemer

griesemer commented on Aug 28, 2020

@griesemer
Contributor

This is a variation of the same problem that plagues #39758. It's not yet implemented and thus leads to odd errors.

modified the milestones: Unreleased, Go1.17 on Feb 24, 2021
griesemer

griesemer commented on Apr 14, 2021

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

modified the milestones: Go1.17, Unreleased on Apr 14, 2021
ianlancetaylor

ianlancetaylor commented on Apr 14, 2021

@ianlancetaylor
Contributor

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

removed their assignment
on Apr 14, 2021
YoshikiShibata

YoshikiShibata commented on Nov 25, 2022

@YoshikiShibata
Author

Now this is no issue.

locked and limited conversation to collaborators on Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @YoshikiShibata@ianlancetaylor@griesemer@gopherbot

        Issue actions

          cmd/go2go: cannot infer T in an embedded field. · Issue #40814 · golang/go