Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
src/pkg/fmt/fmt_test.go
src/pkg/fmt/fmt_test.go
+12
-0
src/pkg/fmt/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