Skip to content

Possible issue with SourceLengthHelper::stripMultilineComments ? #869

Description

@Numpsy

Hi,

I was having a look at the code around

as it seems quite allocation heavy, and when looking noticed that it didn't appear to behave correctly when there are multiple block comments present, as it removes the blocks starting from the start of the source string, and each removal changes the offsets of any following comments.

Basically, If I add a new test like

    [<Test>]
    member this.FunctionTooManyLinesWithMultiLineComments() =
        this.Parse($"""
module Program

let dog x =
    (*
    Foo
    Bar
    *)
    (*
    Foo
    Bar
    *)
    %s{generateNewLines (FunctionLength - 8) 4}
    ()""")
        Assert.IsFalse this.ErrorsExist

Then the generated source is

dog x =
    (*
    Foo
    Bar
    *)
    (*
    Foo
    Bar
    *)
    printf System.String.Empty
    printf System.String.Empty
    printf System.String.Empty
    printf System.String.Empty
    printf System.String.Empty

...

And after stripMultilineComments has run it looks like

dog x =
    
    (*
    Foo
    Bar
    *).Empty
    printf System.String.Empty
    printf System.String.Empty
    printf System.String.Empty
    printf System.String.Empty

...

Which doesn't seem right?
Basically I wonder if it should maybe be removing the blocks in reverse order (starting from the one latest in the file), so the offsets for earlier comments don't change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions