Skip to content

Commit

Permalink
cue/token: NoPos is smaller than any valid position
Browse files Browse the repository at this point in the history
Make Pos.Compare follow the documented behavior.
Tweak the docs to be clearer and use doc links too.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I57ed1a34d5aa9f9066036182e5692a461c11049d
Dispatch-Trailer: {"type":"trybot","CL":1206370,"patchset":1,"ref":"refs/changes/70/1206370/1","targetBranch":"master"}
  • Loading branch information
mvdan authored and cueckoo committed Dec 27, 2024
1 parent ecd814a commit ca6293a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cue/token/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ func (p Pos) Compare(p2 Pos) int {
if p == p2 {
return 0
} else if p == NoPos {
return 1
} else if p2 == NoPos {
// As the documentation for [NoPos] says, it's always smaller than any other position.
return -1
} else if p2 == NoPos {
return +1
}
pos, pos2 := p.Position(), p2.Position()
if c := cmp.Compare(pos.Filename, pos2.Filename); c != 0 {
Expand All @@ -129,10 +130,10 @@ func (p Pos) Compare(p2 Pos) int {

}

// NoPos is the zero value for Pos; there is no file and line information
// NoPos is the zero value for [Pos]; there is no file and line information
// associated with it, and [Pos.IsValid] is false. NoPos is always
// smaller than any other Pos value. The corresponding Position value
// for NoPos is the zero value for Position.
// smaller than any valid [Pos] value. The corresponding [Position] value
// for NoPos is the zero value.
var NoPos = Pos{}

// RelPos indicates the relative position of token to the previous token.
Expand Down

0 comments on commit ca6293a

Please sign in to comment.