Skip to content

FS0193: internal error: startIndex cannot be larger than length of string. (Parameter 'startIndex') #18402

@IS4Code

Description

@IS4Code

I have noticed some very strange behaviour related to line directives, which in some cases lead to compiler errors.

Repro steps
This exact piece of code shows the behaviour:

open System

# 10
FSharp.Core.ExtraTopLevelOperators.printfn "%s" "ab"

# 15



// end

Expected behavior

The code should compile fine and print ab when executed.

Actual behavior

FS0193:10: internal error: startIndex cannot be larger than length of string. (Parameter 'startIndex')

Also, very strangely, if I remove FSharp.Core.ExtraTopLevelOperators., I get another strange error:

FS0001:10: This expression was expected to have type
''a -> 'b'
but here has type
'unit'

And, if I instead replace it with do , I get:

FS0193:10: internal error: Index and length must refer to a location within the string. (Parameter 'length')

I don't think the particular sequences I replace it with matter, it seems to be more a line position thing.

Known workarounds

I did not manage to find a workaround that preserves the line information. I would certainly appreciate a solution that works for older compilers.

Related information

Tested on .NET SDK 9.0.201.
Examples:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-Syntaxlexfilter, indentation and parsingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    No fields configured for Bug.

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions