In FSI, an invalid string literal can break further parsing of string in that interactive session
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
In FSI, inputting an interpolated string literal that opens interpolation expression with `{` but does not close it, e.g. `$"{"` breaks the session in a way that further valid string literals can no longer be parsed
**Repro steps**
In `dotnet fsi` try:
```fsi
> $"{";;
```
followed by any(?) string literal, e.g. empty string:
```fsi
> "";;
```
Full session example:
```fsi
# dotnet fsi
Microsoft (R) F# Interactive version 12.0.5.0 for F# 7.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> $"{";;
$"{";;
---^
stdin(1,4): error FS3373: Invalid interpolated string. Single quote or verbatim string literals may not be used in interpolated expressions in single quote or verbatim strings. Consider using an explicit 'let' binding for the interpolation expression or use a triple quote string as the outer string literal.
> "";;
"";;
^
stdin(2,1): error FS3373: Invalid interpolated string. Single quote or verbatim string literals may not be used in interpolated expressions in single quote or verbatim strings. Consider using an explicit 'let' binding for the interpolation expression or use a triple quote string as the outer string literal.
$"{";;
-----^
stdin(1,6): error FS3373: Invalid interpolated string. Single quote or verbatim string literals may not be used in interpolated expressions in single quote or verbatim strings. Consider using an explicit 'let' binding for the interpolation expression or use a triple quote string as the outer string literal.
> > ;;
> "";;
;;
^
stdin(3,1): error FS3373: Invalid interpolated string. Single quote or verbatim string literals may not be used in interpolated expressions in single quote or verbatim strings. Consider using an explicit 'let' binding for the interpolation expression or use a triple quote string as the outer string literal.
"";;
--^
stdin(2,3): error FS3373: Invalid interpolated string. Single quote or verbatim string literals may not be used in interpolated expressions in single quote or verbatim strings. Consider using an explicit 'let' binding for the interpolation expression or use a triple quote string as the outer string literal.
> >
```
Note: the invalid input results in "error FS3373: Invalid interpolated string", however not all inputs that result in this particular error are followed by this buggy behavior, e.g. `$"{""}"` or `$"{"}"` result in error FS3373, but don't break the session.
**Expected behavior**
Valid string literals are parsed correctly, regardless of erroneous input that happened earlier in that same interactive session.
**Actual behavior**
Certain inputs make FSI unable to parse valid strings afterwards.
**Known workarounds**
Close FSI session and open a new one
**Related information**
Provide any related information (optional):
* Operating system: Windows 11
* .NET Runtime kind: dotnet core `7.0.100-rc.2.22477.23`
Contributor guide
Assessment
This issue has not been assessed yet.