waf / CSharpRepl

A command line C# REPL with syntax highlighting – explore the language, libraries and nuget packages interactively.
https://fuqua.io/CSharpRepl/
Mozilla Public License 2.0
2.76k stars 106 forks source link

Curly braces in strings manipulate the indentation level #379

Open SnipUndercover opened 1 month ago

SnipUndercover commented 1 month ago

Version

C# REPL 0.6.7+d2955f13e744320cd6331c484e1286c3ed4f8612

What happened?

Entering curly braces ({}) in strings manipulates the current indentation level, despite being regular characters in this context.

This can be reproduced by entering the following snippet:

{
    var _ = "}";

Pressing Enter at this point will dedent the next line, which is unexpected. After entering a statement, adding a semicolon (;) or closing curly brace (}) will fix the indentation, like so:

{
    var _ = "}";
Console.WriteLine()  // putting a ; or } here will fix the indentation

Because the level of indentation is now desynced, closing the code block by adding another closing brace (}) will set the indentation level to -1. Pressing Shift+Enter at this point will crash the REPL; see #378.