Skip to content

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

@abonie

Description

@abonie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FSIBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    Projects

    Status

    In Progress

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions