Skip to content

cmd/compile: type inference failing for nested type parameters #39661

Closed
@DeedleFake

Description

@DeedleFake

Filing a bug as per #15292 (comment).

If a function is called that takes an argument of a generic type that in turn has its own type parameter, the inference of the subtype fails. For example,

Playground

package main

type Getter(type T) interface {
	Get() T
}

type Impl struct {
	v string
}

func (i Impl) Get() string {
	return i.v
}

func Bug(type G Getter(T), T interface{})(g G) {
}

func main() {
	i := Impl{v: "example"}
	Bug(i)
}

Output:

type checking failed for main
prog.go2:20:7: cannot infer T (prog.go2:15:28)

This code works if the call to Bug is changed to Bug(Impl, string).

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.TypeInferenceIssue is related to generic type inferencecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions