fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

In FSI, an invalid string literal can break further parsing of string in that interactive session

Open abonie opened this issue 3 years ago • 8 comments

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:

> $"{";;

followed by any(?) string literal, e.g. empty string:

> "";;

Full session example:

# 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

abonie avatar Oct 21 '22 16:10 abonie

I think I incidentally stumbled upon a solution as I've been working on lexing recently, so I am looking into this issue.

No clue how to unit test this yet though.

abonie avatar Oct 26 '22 14:10 abonie

Reopening as https://github.com/dotnet/fsharp/pull/14182 had to be reverted due to https://github.com/dotnet/fsharp/issues/14757

abonie avatar Feb 16 '23 16:02 abonie

I have a similiar behavior (broker parsing) that doesn't involve "{", should I open a different issue ?

let cst = "Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@37d688b1-org.sonar.scanner.bootstrap.ScannerPluginRepository': Initialization of bean failed"

Send it 4 times to FSI

  • works fine
  • works fine
  • shows the command but doesn't print the variable
  • breaks

FSI

Microsoft (R) F# Interactive version 12.5.0.0 for F# 7.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> # silentCd @"/home/vince/src/github/mrluje/fs-gitlab-stats";;
- # 1 @"/home/vince/src/github/mrluje/fs-gitlab-stats/test.fsx"
- ;;
> let cst = "Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@37d688b1-org.sonar.scanner.bootstrap.ScannerPluginRepository': Initialization of bean failed";;
val cst: string =  "Error creating bean with name 'org.sonarsource.scanner.api.in"+[119 chars]

> let cst = "Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@37d688b1-org.sonar.scanner.bootstrap.ScannerPluginRepository': Initialization of bean failed";;
val cst: string =  "Error creating bean with name 'org.sonarsource.scanner.api.in"+[119 chars]

> ";; cst = "Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@37d688b1-org.sonar.scanner.bootstrap.ScannerPluginRepository': Initialization of bean faile
- let cst = "Error creating bean with name 'org.sonarsource.scanner.api.internal.IsolatedClassloader@37d688b1-org.sonar.scanner.bootstrap.ScannerPluginRepository': Initialization of bean faile

error FS0193: Operation is not supported on this platform.

> ";;
- 

MrLuje avatar Apr 28 '23 12:04 MrLuje

@MrLuje how are you sending the input to FSI in your example? Because it looks like the input got mangled the third time it was sent. Does not seem to be the same issue.

abonie avatar Jun 19 '23 09:06 abonie

@abonie with ionide extension (v7.7.0) on vscode with either "FSI: send selection" or "FSI: send line"

MrLuje avatar Jun 19 '23 10:06 MrLuje

Hmm... It does not repro for me at least on the same version of ionide

abonie avatar Jun 22 '23 13:06 abonie

I didn't check before but it looks like it is only failing from WSL

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

$ uname -a
Linux HVS-PF346A2W 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

I can't reproduce it either from windows

MrLuje avatar Jun 22 '23 16:06 MrLuje

@abonie : Is this still relevant?

T-Gro avatar Jul 31 '24 17:07 T-Gro