Skip to content

ISourceText equality comparison fails #9799

@deviousasti

Description

@deviousasti

This being a container for a source string, while identical SourceTexts will have the same hash code, it fails for equality testing because a StringText object is compared to the other's source text, which is always false.

The implementation in prim-lexing.fs:

    override __.GetHashCode() = str.GetHashCode()
    override __.Equals(obj: obj) = str.Equals(obj)

This behavior breaks dictionaries and sets.

Repro:

    let text = "()"
    let source1 = FSharp.Compiler.Text.SourceText.ofString text
    let source2 = FSharp.Compiler.Text.SourceText.ofString text

    assert(source1.GetHashCode() = source2.GetHashCode()) //works
    assert(source1 = source2) //fails

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions