Skip to content

cmd/compile: cannot convert untyped string value to type parameter constrained by ~string | ~[]byte #51386

Closed

Description

@dominikh

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

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Feb 27, 2022
  2. added this to the Go1.18 milestone on Feb 27, 2022
  3. self-assigned this
    on Feb 27, 2022
  4. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Feb 27, 2022
  5. griesemer commented on Feb 27, 2022

    @griesemer
    Contributor

    Looks like a bug to me.

  6. removed
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Feb 27, 2022
  7. griesemer commented on Feb 27, 2022

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

    this works

  8. gopherbot commented on Feb 28, 2022

    @gopherbot
    Contributor

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

  9. locked and limited conversation to collaborators on Jun 22, 2023
  10. added a commit that references this issue on Apr 29, 2024
    f928581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions