From 10620da52c6ee0c775a8ef8d3d4e32b35bcf7f29 Mon Sep 17 00:00:00 2001 From: asti Date: Mon, 27 Jul 2020 14:13:54 +0530 Subject: [PATCH 1/2] Add ToString to FSharp.Compiler.Text.StringText There exists no method to retrieve the original source string because the 'String' property on StringText is never exposed in ISourceText --- src/utils/prim-lexing.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/prim-lexing.fs b/src/utils/prim-lexing.fs index 1f772d6e87e..b849fd7ed48 100644 --- a/src/utils/prim-lexing.fs +++ b/src/utils/prim-lexing.fs @@ -53,6 +53,7 @@ type StringText(str: string) = override __.GetHashCode() = str.GetHashCode() override __.Equals(obj: obj) = str.Equals(obj) + override __.ToString() = str interface ISourceText with From eaaf1cfed1a11dcb6002efc0f293f6bd6cd5483a Mon Sep 17 00:00:00 2001 From: asti Date: Mon, 27 Jul 2020 14:34:26 +0530 Subject: [PATCH 2/2] 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. --- src/utils/prim-lexing.fs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/prim-lexing.fs b/src/utils/prim-lexing.fs index b849fd7ed48..151052b5f80 100644 --- a/src/utils/prim-lexing.fs +++ b/src/utils/prim-lexing.fs @@ -52,7 +52,11 @@ type StringText(str: string) = member __.String = str override __.GetHashCode() = str.GetHashCode() - override __.Equals(obj: obj) = str.Equals(obj) + override __.Equals(obj: obj) = + match obj with + | :? StringText as other -> other.String.Equals(str) + | :? string as other -> other.Equals(str) + | _ -> false override __.ToString() = str interface ISourceText with