Skip to content

cmd/go2go: compiler treats returning type with generics incorrectly. #39655

Closed
@googollee

Description

@googollee

What version of Go are you using (go version)?

$ go version
devel +ad307489d4 Tue Jun 16 05:49:35 2020 +0000.

Does this issue reproduce with the latest release?

No. It's a dev branch.

What operating system and processor architecture are you using (go env)?

I'm using https://go2goplay.golang.org/.

What did you do?

package main

type Result(type T) struct {
	t T
}

func F(type T)(v Result(T)) (Result(T)) {
	return v
}

What did you expect to see?

The code should be compiled

What did you see instead?

type checking failed for main
prog.go2:8:9: cannot use v (variable of type Result(T)) as T value in return statement

The return type of F should be Result(T), but the compiler thinks it's T, treating the definition as func F(type T)(v Result(T)) (Result T).

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions