]> Cypherpunks repositories - gostls13.git/commitdiff
make String work on Position values, to enable
authorRuss Cox <rsc@golang.org>
Wed, 16 Sep 2009 23:38:49 +0000 (16:38 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 16 Sep 2009 23:38:49 +0000 (16:38 -0700)
fmt.Printf("%s: %s\n", expr.Pos(), message);

R=gri
DELTA=15  (1 added, 3 deleted, 11 changed)
OCL=34706
CL=34708

src/pkg/go/token/token.go

index e0ee0decf9a9082d49f222c90e9802da1317e326..1ea6c46e9d2972280b8015704c94c1b664fa5aae 100644 (file)
@@ -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;
 }