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/compile: cannot convert untyped string value to type parameter constrained by ~string | ~[]byte #51386

Closed
dominikh opened this issue Feb 27, 2022 · 3 comments
Labels
NeedsFix
Milestone

Comments

@dominikh
Copy link
Member

@dominikh dominikh commented Feb 27, 2022

Input:

package pkg

func foo[T ~string | ~[]byte]() {
	var _ T = T("")
}

Output:

./baz.go:4:14: cannot convert "" (untyped string value) to type T:
	cannot convert "" (untyped string constant) to []byte (in T)

I expected this conversion to work. If it isn't supposed to work, then the error message is confusing.

/cc @griesemer

@dominikh dominikh added the NeedsInvestigation label Feb 27, 2022
@dominikh dominikh added this to the Go1.18 milestone Feb 27, 2022
@griesemer griesemer self-assigned this Feb 27, 2022
@griesemer griesemer added the NeedsFix label Feb 27, 2022
@griesemer
Copy link
Contributor

@griesemer griesemer commented Feb 27, 2022

Looks like a bug to me.

@gopherbot gopherbot removed the NeedsInvestigation label Feb 27, 2022
@griesemer
Copy link
Contributor

@griesemer griesemer commented Feb 27, 2022

func foo[T ~string | ~[]byte]() {
        var s string
	var _ T = T(s)
}

this works

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 28, 2022

Change https://go.dev/cl/388254 mentions this issue: go/types, types2: fix string to type parameter conversions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix
Projects
None yet
Development

No branches or pull requests

3 participants