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

go/types, types2: conversions involving type parameters don't work #47150

Open
griesemer opened this issue Jul 12, 2021 · 0 comments
Open

go/types, types2: conversions involving type parameters don't work #47150

griesemer opened this issue Jul 12, 2021 · 0 comments
Assignees
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jul 12, 2021

Reminder issue that conversions involving type parameters are implemented ad-hoc and don't work as expected.

For instance (https://go2goplay.golang.org/p/8MHhIOoWA29):

package p

type Int interface{ type int }
type String interface{ type string }
type IntOrString interface {
	type int, string
}

func Convert1[Dst Int, Src Int](x Src) Dst            { return Dst(x) }
func Convert2[Dst String, Src Int](x Src) Dst         { return Dst(x) }
func Convert3[Dst String, Src String](x Src) Dst      { return Dst(x) }
func Convert4[Dst IntOrString, Src Int](x Src) Dst    { return Dst(x) }
func Convert5[Dst String, Src IntOrString](x Src) Dst { return Dst(x) }

(test case by @mdempsky)

See also the section on type conversions in the generics proposal.

cc: @findleyr

@griesemer griesemer added this to the Go1.18 milestone Jul 12, 2021
@griesemer griesemer self-assigned this Jul 12, 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
1 participant