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
e73680ae
Commit
e73680ae
authored
Nov 04, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template: format errors
R=golang-dev, r CC=golang-dev
https://golang.org/cl/5340043
parent
cb2040b2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
3 deletions
+7
-3
exec.go
src/pkg/text/template/exec.go
+2
-2
exec_test.go
src/pkg/text/template/exec_test.go
+4
-0
funcs.go
src/pkg/text/template/funcs.go
+1
-1
No files found.
src/pkg/text/template/exec.go
View file @
e73680ae
...
...
@@ -445,7 +445,7 @@ func methodByName(receiver reflect.Value, name string) (reflect.Value, bool) {
}
var
(
osErrorType
=
reflect
.
TypeOf
((
*
error
)(
nil
))
.
Elem
()
errorType
=
reflect
.
TypeOf
((
*
error
)(
nil
))
.
Elem
()
fmtStringerType
=
reflect
.
TypeOf
((
*
fmt
.
Stringer
)(
nil
))
.
Elem
()
)
...
...
@@ -659,7 +659,7 @@ func (s *state) printValue(n parse.Node, v reflect.Value) {
return
}
if
!
v
.
Type
()
.
Implements
(
fmtStringerType
)
{
if
!
v
.
Type
()
.
Implements
(
errorType
)
&&
!
v
.
Type
()
.
Implements
(
fmtStringerType
)
{
if
v
.
CanAddr
()
&&
reflect
.
PtrTo
(
v
.
Type
())
.
Implements
(
fmtStringerType
)
{
v
=
v
.
Addr
()
}
else
{
...
...
src/pkg/text/template/exec_test.go
View file @
e73680ae
...
...
@@ -6,6 +6,7 @@ package template
import
(
"bytes"
"errors"
"flag"
"fmt"
"os"
...
...
@@ -52,6 +53,7 @@ type T struct {
NonEmptyInterface
I
// Stringer.
Str
fmt
.
Stringer
Err
error
// Pointers
PI
*
int
PSI
*
[]
int
...
...
@@ -99,6 +101,7 @@ var tVal = &T{
Empty4
:
&
U
{
"UinEmpty"
},
NonEmptyInterface
:
new
(
T
),
Str
:
bytes
.
NewBuffer
([]
byte
(
"foozle"
)),
Err
:
errors
.
New
(
"erroozle"
),
PI
:
newInt
(
23
),
PSI
:
newIntSlice
(
21
,
22
,
23
),
Tmpl
:
Must
(
New
(
"x"
)
.
Parse
(
"test template"
)),
// "x" is the value of .X
...
...
@@ -416,6 +419,7 @@ var execTests = []execTest{
{
"bug4"
,
"{{if .Empty0}}non-nil{{else}}nil{{end}}"
,
"nil"
,
tVal
,
true
},
// Stringer.
{
"bug5"
,
"{{.Str}}"
,
"foozle"
,
tVal
,
true
},
{
"bug5a"
,
"{{.Err}}"
,
"erroozle"
,
tVal
,
true
},
// Args need to be indirected and dereferenced sometimes.
{
"bug6a"
,
"{{vfunc .V0 .V1}}"
,
"vfunc"
,
tVal
,
true
},
{
"bug6b"
,
"{{vfunc .V0 .V0}}"
,
"vfunc"
,
tVal
,
true
},
...
...
src/pkg/text/template/funcs.go
View file @
e73680ae
...
...
@@ -72,7 +72,7 @@ func goodFunc(typ reflect.Type) bool {
switch
{
case
typ
.
NumOut
()
==
1
:
return
true
case
typ
.
NumOut
()
==
2
&&
typ
.
Out
(
1
)
==
osE
rrorType
:
case
typ
.
NumOut
()
==
2
&&
typ
.
Out
(
1
)
==
e
rrorType
:
return
true
}
return
false
...
...
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