Skip to content

gc compiler error: does not accept legal string to []byte conversion #1709

@griesemer

Description

@griesemer
6g test2.go && 6l test2.6 && 6.out
test2.go:6: cannot use ts (type Ts) as type string in function argument

package main

func main() {
    type Ts string
    var ts Ts
    _ = []byte(ts)
}

This code is accepted by gccgo; it is legal according to the spec, ts is of string type
(as opposed to type string):

"Converting a value of a string type to []byte (or []uint8) yields a slice whose
successive elements are the bytes of the string."

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions