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

fmt: []T handled like []byte for 'type T byte' #8360

Closed
rsc opened this issue Jul 11, 2014 · 3 comments
Closed

fmt: []T handled like []byte for 'type T byte' #8360

rsc opened this issue Jul 11, 2014 · 3 comments
Assignees
Milestone

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Jul 11, 2014

http://play.golang.org/p/gii_KLkBJF

package main

import "fmt"

type Tuint8 uint8

func (t Tuint8) String() string { return "Tuint8" }

type Tint8 int8

func (t Tint8) String() string { return "Tint8" }

func main() {
    fmt.Println("[]Tint8:", []Tint8{1,2,3})
    fmt.Println("[]Tuint8:", []Tuint8{1,2,3})
    fmt.Println("[]byte:", []byte{1,2,3})
}

should probably print

[]Tint8: [Tint8 Tint8 Tint8]
[]Tuint8: [Tuint8 Tuint8 Tuint8]
[]byte: [1 2 3]

but prints

[]Tint8: [Tint8 Tint8 Tint8]
[]Tuint8: [1 2 3]
[]byte: [1 2 3]

The check for []byte should only apply to []byte (and the indistinguishable []uint8) but
not to [] of a typed byte.
@rsc
Copy link
Contributor Author

@rsc rsc commented Jul 11, 2014

Comment 1:

Labels changed: added repo-main.

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 18, 2014

Comment 2:

CL https://golang.org/cl/129330043 mentions this issue.
@adg
Copy link
Contributor

@adg adg commented Aug 18, 2014

Comment 3:

This issue was closed by revision 326f48e.

Status changed to Fixed.

@rsc rsc added fixed labels Aug 18, 2014
@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
type T byte
func (T) String() string { return "X" }

fmt.Sprintf("%s", []T{97, 98, 99, 100}) == "abcd"
fmt.Sprintf("%x", []T{97, 98, 99, 100}) == "61626364"
fmt.Sprintf("%v", []T{97, 98, 99, 100}) == "[X X X X]"

This change makes the last case print correctly.
Before, it would have been "[97 98 99 100]".

Fixes golang#8360.

LGTM=r
R=r, dan.kortschak
CC=golang-codereviews
https://golang.org/cl/129330043
wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
type T byte
func (T) String() string { return "X" }

fmt.Sprintf("%s", []T{97, 98, 99, 100}) == "abcd"
fmt.Sprintf("%x", []T{97, 98, 99, 100}) == "61626364"
fmt.Sprintf("%v", []T{97, 98, 99, 100}) == "[X X X X]"

This change makes the last case print correctly.
Before, it would have been "[97 98 99 100]".

Fixes golang#8360.

LGTM=r
R=r, dan.kortschak
CC=golang-codereviews
https://golang.org/cl/129330043
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.