Skip to content

Commit 6ae361f

Browse files
deviousastibaronfel
authored andcommitted
Fix equality comparison for StringText
This being a container for a source string, while identical StringTexts will have the same GetHashCode(), it fails for equality testing because a StringText object is compared to the other's source text, which is always false. The comparison to string behavior is retained.
1 parent cc618bf commit 6ae361f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/utils/prim-lexing.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ type StringText(str: string) =
5252
member __.String = str
5353

5454
override __.GetHashCode() = str.GetHashCode()
55-
override __.Equals(obj: obj) = str.Equals(obj)
55+
override __.Equals(obj: obj) =
56+
match obj with
57+
| :? StringText as other -> other.String.Equals(str)
58+
| :? string as other -> other.Equals(str)
59+
| _ -> false
5660
override __.ToString() = str
5761

5862
interface ISourceText with

0 commit comments

Comments
 (0)