dotnet / dotnet/fsharp

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

Open
#18,402 0 comments 2 reactions 0 assignees View on GitHub
Area-Compiler-Syntax Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

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:
```fs
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:
* https://sharplab.io/#v2:DYLgZgzgPg9gDgUwHYAIDKBPCAXBBbAWAChiBiFARgAZiAxNACwEMAnOAOgGEYWF2BRAB7YWTACrwAMggBuCYAHlEo7Dwjs4LAJZJsYVACIApBAMoDTAEYHiZSgFZbJZwHoXKZABMgA=
* https://sharplab.io/#v2:DYLgZgzgPg9gDgUwHYAIDKBPCAXBBbAWAChiBiFARgAZi4AnASyWzFQCIBSCNlNgQwBGbYmUoBWESSnEA9DJTIAJkA==
* https://sharplab.io/#v2:DYLgZgzgPg9gDgUwHYAIDKBPCAXBBbAWAChiBiFARgAZi4AnASyWzFQCIBSCNlNgQwBGbYmUoBWESSmTJAelkpkAEyA=

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.