Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
a308be5f
Commit
a308be5f
authored
Jun 25, 2012
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fmt: set p.field before nil check
Fixes #3752. R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/6331062
parent
d1537809
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
fmt_test.go
src/pkg/fmt/fmt_test.go
+12
-0
print.go
src/pkg/fmt/print.go
+3
-2
No files found.
src/pkg/fmt/fmt_test.go
View file @
a308be5f
...
@@ -851,3 +851,15 @@ func TestIsSpace(t *testing.T) {
...
@@ -851,3 +851,15 @@ func TestIsSpace(t *testing.T) {
}
}
}
}
}
}
func
TestNilDoesNotBecomeTyped
(
t
*
testing
.
T
)
{
type
A
struct
{}
type
B
struct
{}
var
a
*
A
=
nil
var
b
B
=
B
{}
got
:=
Sprintf
(
"%s %s %s %s %s"
,
nil
,
a
,
nil
,
b
,
nil
)
const
expect
=
"%!s(<nil>) %!s(*fmt_test.A=<nil>) %!s(<nil>) {} %!s(<nil>)"
if
got
!=
expect
{
t
.
Errorf
(
"expected:
\n\t
%q
\n
got:
\n\t
%q"
,
expect
,
got
)
}
}
src/pkg/fmt/print.go
View file @
a308be5f
...
@@ -712,6 +712,9 @@ func (p *pp) handleMethods(verb rune, plus, goSyntax bool, depth int) (wasString
...
@@ -712,6 +712,9 @@ func (p *pp) handleMethods(verb rune, plus, goSyntax bool, depth int) (wasString
}
}
func
(
p
*
pp
)
printField
(
field
interface
{},
verb
rune
,
plus
,
goSyntax
bool
,
depth
int
)
(
wasString
bool
)
{
func
(
p
*
pp
)
printField
(
field
interface
{},
verb
rune
,
plus
,
goSyntax
bool
,
depth
int
)
(
wasString
bool
)
{
p
.
field
=
field
p
.
value
=
reflect
.
Value
{}
if
field
==
nil
{
if
field
==
nil
{
if
verb
==
'T'
||
verb
==
'v'
{
if
verb
==
'T'
||
verb
==
'v'
{
p
.
buf
.
Write
(
nilAngleBytes
)
p
.
buf
.
Write
(
nilAngleBytes
)
...
@@ -721,8 +724,6 @@ func (p *pp) printField(field interface{}, verb rune, plus, goSyntax bool, depth
...
@@ -721,8 +724,6 @@ func (p *pp) printField(field interface{}, verb rune, plus, goSyntax bool, depth
return
false
return
false
}
}
p
.
field
=
field
p
.
value
=
reflect
.
Value
{}
// Special processing considerations.
// Special processing considerations.
// %T (the value's type) and %p (its address) are special; we always do them first.
// %T (the value's type) and %p (its address) are special; we always do them first.
switch
verb
{
switch
verb
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment