diff options
author | Russ Cox <rsc@golang.org> | 2009-09-16 16:38:49 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-09-16 16:38:49 -0700 |
commit | 3cea70516722c910d12fd28cbeb4aabb9d2873df (patch) | |
tree | fb890d0c671313a8776103133cde89438baa1431 /src | |
parent | 111276355791f987f8afa11068acec498380b1ea (diff) | |
download | golang-3cea70516722c910d12fd28cbeb4aabb9d2873df.tar.gz |
make String work on Position values, to enable
fmt.Printf("%s: %s\n", expr.Pos(), message);
R=gri
DELTA=15 (1 added, 3 deleted, 11 changed)
OCL=34706
CL=34708
Diffstat (limited to 'src')
-rw-r--r-- | src/pkg/go/token/token.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/pkg/go/token/token.go b/src/pkg/go/token/token.go index e0ee0decf..1ea6c46e9 100644 --- a/src/pkg/go/token/token.go +++ b/src/pkg/go/token/token.go @@ -352,18 +352,16 @@ func (pos *Position) IsValid() bool { } -func (pos *Position) String() string { - if pos != nil { - s := pos.Filename; - if pos.IsValid() { - if s != "" { - s += ":"; - } - s += fmt.Sprintf("%d:%d", pos.Line, pos.Column); - } +func (pos Position) String() string { + s := pos.Filename; + if pos.IsValid() { if s != "" { - return s; + s += ":"; } + s += fmt.Sprintf("%d:%d", pos.Line, pos.Column); + } + if s == "" { + s = "???"; } - return "<unknown position>"; + return s; } |