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
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dominikh
Copy link
Member

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. 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 The path to resolution is known, but the work has not been done. label Feb 27, 2022
@griesemer
Copy link
Contributor

Looks like a bug to me.

@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 27, 2022
@griesemer
Copy link
Contributor

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

this works

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants