Skip to content

Commit d1a2786

Browse files
committed
Fix keyword compare
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
1 parent 8de2803 commit d1a2786

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

pkg/lang/keyword.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,27 @@ func (k Keyword) Hash() uint32 {
101101

102102
func (k Keyword) Compare(other any) int {
103103
if otherKw, ok := other.(Keyword); ok {
104-
return strings.Compare(k.String(), otherKw.String())
104+
s := k.String()
105+
os := otherKw.String()
106+
if s == os {
107+
return 0
108+
}
109+
ns := k.Namespace()
110+
if ns == "" {
111+
if otherKw.Namespace() != "" {
112+
return -1
113+
}
114+
} else {
115+
ons := otherKw.Namespace()
116+
if ons == "" {
117+
return 1
118+
}
119+
nsc := strings.Compare(ns, ons)
120+
if nsc != 0 {
121+
return nsc
122+
}
123+
}
124+
return strings.Compare(k.Name(), otherKw.Name())
105125
}
106126
panic(NewIllegalArgumentError(fmt.Sprintf("Cannot compare Keyword with %T", other)))
107127
}

0 commit comments

Comments
 (0)