Skip to content

Negative indentation levels crash the REPL #378

Open
@SnipUndercover

Description

Version

C# REPL 0.6.7+d2955f13e744320cd6331c484e1286c3ed4f8612

What happened?

If the indentation level becomes negative, the REPL crashes.
This can be reproduced by entering a singular closing brace (}) and pressing Shift+Enter.
The closing brace can also be inside a string; see #379.

Trace log
2024-08-07T20:51:33 - Trace session starting
2024-08-07T20:51:33 - Starting background initialization
2024-08-07T20:51:33 - Discovered dotnet version .NET Core SDK 8.0.204 at C:\Program Files\dotnet\sdk\8.0.204.
2024-08-07T20:51:33 - Available Reference Assemblies: "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref": ["3.1.0", "5.0.0", "6.0.29", "7.0.18", "7.0.20", "8.0.4", "8.0.7"]
2024-08-07T20:51:33 - Available Implementation Assemblies: "C:\Program Files\dotnet\shared\Microsoft.NETCore.App": ["2.1.30", "3.1.32", "5.0.11", "5.0.17", "5.0.4", "6.0.28", "6.0.29", "6.0.32", "7.0.18", "7.0.20", "8.0.4", "8.0.7"]
2024-08-07T20:51:34 - .NET Version: Microsoft.NETCore.App / 8.0.7
2024-08-07T20:51:34 - Reference Assembly Paths: C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.7\ref\net8.0
2024-08-07T20:51:34 - Implementation Assembly Paths: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.7
2024-08-07T20:51:34 - Shared Framework Paths: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.7
2024-08-07T20:51:34 - Loaded Reference Assemblies: "C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.7\ref\net8.0": ["System.Threading.Tasks.Parallel.dll", "System.Globalization.dll", "System.IO.FileSystem.Primitives.dll", "System.Security.Cryptography.Primitives.dll", "System.Threading.Thread.dll", "System.Globalization.Extensions.dll", "System.IO.FileSystem.Watcher.dll", "System.Security.Cryptography.X509Certificates.dll", "System.Threading.ThreadPool.dll", "System.IO.Compression.Brotli.dll", "System.IO.IsolatedStorage.dll", "System.Security.dll", "System.Threading.Timer.dll", "System.IO.Compression.dll", "System.IO.MemoryMappedFiles.dll", "System.Security.Principal.dll", "System.Transactions.dll", "System.IO.Compression.FileSystem.dll", "System.IO.Pipes.AccessControl.dll", "System.Security.Principal.Windows.dll", "System.Transactions.Local.dll", "System.IO.Compression.ZipFile.dll", "System.IO.Pipes.dll", "System.Security.SecureString.dll", "System.ValueTuple.dll", "System.IO.dll", "System.IO.UnmanagedMemoryStream.dll", "System.ServiceModel.Web.dll", "System.Web.dll", "System.IO.FileSystem.AccessControl.dll", "System.Linq.dll", "System.ServiceProcess.dll", "System.Web.HttpUtility.dll", "System.IO.FileSystem.dll", "System.Linq.Expressions.dll", "System.Text.Encoding.CodePages.dll", "System.Windows.dll", "System.IO.FileSystem.DriveInfo.dll", "System.Linq.Parallel.dll", "System.Text.Encoding.dll", "System.Runtime.Serialization.Primitives.dll", "System.Net.WebSockets.dll", "System.Runtime.Serialization.Xml.dll", "System.Numerics.dll", "System.Security.AccessControl.dll", "System.Numerics.Vectors.dll", "System.Security.Claims.dll", "System.ObjectModel.dll", "System.Security.Cryptography.Algorithms.dll", "System.Reflection.DispatchProxy.dll", "System.Security.Cryptography.Cng.dll", "System.Reflection.dll", "System.Security.Cryptography.Csp.dll", "System.Reflection.Emit.dll", "System.Security.Cryptography.dll", "System.Reflection.Emit.ILGeneration.dll", "System.Security.Cryptography.Encoding.dll", "System.Reflection.Emit.Lightweight.dll", "System.Security.Cryptography.OpenSsl.dll", "System.Reflection.Extensions.dll", "System.Diagnostics.Tools.dll", "System.Diagnostics.TraceSource.dll", "System.Diagnostics.Tracing.dll", "System.dll", "System.Drawing.dll", "System.Drawing.Primitives.dll", "System.Dynamic.Runtime.dll", "System.Formats.Asn1.dll", "System.Formats.Tar.dll", "System.Globalization.Calendars.dll", "System.Net.Primitives.dll", "System.Net.Quic.dll", "System.Net.Requests.dll", "System.Net.Security.dll", "System.Net.ServicePoint.dll", "System.Net.Sockets.dll", "System.Net.WebClient.dll", "System.Net.WebHeaderCollection.dll", "System.Net.WebProxy.dll", "System.Net.WebSockets.Client.dll", "System.Linq.Queryable.dll", "System.Memory.dll", "System.Net.dll", "System.Net.Http.dll", "System.Net.Http.Json.dll", "System.Net.HttpListener.dll", "System.Net.Mail.dll", "System.Net.NameResolution.dll", "System.Net.NetworkInformation.dll", "System.Net.Ping.dll", "Microsoft.CSharp.dll", "Microsoft.VisualBasic.Core.dll", "Microsoft.VisualBasic.dll", "Microsoft.Win32.Primitives.dll", "Microsoft.Win32.Registry.dll", "mscorlib.dll", "netstandard.dll", "System.AppContext.dll", "System.Buffers.dll", "System.Collections.Concurrent.dll", "System.Collections.dll", "System.Reflection.Metadata.dll", "System.Text.Encoding.Extensions.dll", "System.Reflection.Primitives.dll", "System.Text.Encodings.Web.dll", "System.Reflection.TypeExtensions.dll", "System.Text.Json.dll", "System.Resources.Reader.dll", "System.Text.RegularExpressions.dll", "System.Resources.ResourceManager.dll", "System.Threading.Channels.dll", "System.Resources.Writer.dll", "System.Threading.dll", "System.Runtime.CompilerServices.Unsafe.dll", "System.Threading.Overlapped.dll", "System.Runtime.CompilerServices.VisualC.dll", "System.Threading.Tasks.Dataflow.dll", "System.Runtime.dll", "System.Threading.Tasks.dll", "System.Runtime.Extensions.dll", "System.Threading.Tasks.Extensions.dll", "System.Runtime.Handles.dll", "System.Runtime.InteropServices.dll", "System.Runtime.InteropServices.JavaScript.dll", "System.Runtime.InteropServices.RuntimeInformation.dll", "System.Runtime.Intrinsics.dll", "System.Runtime.Loader.dll", "System.Runtime.Numerics.dll", "System.Runtime.Serialization.dll", "System.Runtime.Serialization.Formatters.dll", "System.Runtime.Serialization.Json.dll", "System.Core.dll", "System.Data.Common.dll", "System.Data.DataSetExtensions.dll", "System.Data.dll", "System.Diagnostics.Contracts.dll", "System.Diagnostics.Debug.dll", "System.Diagnostics.DiagnosticSource.dll", "System.Diagnostics.FileVersionInfo.dll", "System.Diagnostics.Process.dll", "System.Diagnostics.StackTrace.dll", "System.Diagnostics.TextWriterTraceListener.dll", "System.Collections.Immutable.dll", "System.Collections.NonGeneric.dll", "System.Collections.Specialized.dll", "System.ComponentModel.Annotations.dll", "System.ComponentModel.DataAnnotations.dll", "System.ComponentModel.dll", "System.ComponentModel.EventBasedAsync.dll", "System.ComponentModel.Primitives.dll", "System.ComponentModel.TypeConverter.dll", "System.Configuration.dll", "System.Console.dll", "System.Xml.dll", "System.Xml.Linq.dll", "System.Xml.ReaderWriter.dll", "System.Xml.Serialization.dll", "System.Xml.XDocument.dll", "System.Xml.XmlDocument.dll", "System.Xml.XmlSerializer.dll", "System.Xml.XPath.dll", "System.Xml.XPath.XDocument.dll", "WindowsBase.dll"]
2024-08-07T20:51:34 - Loaded Implementation Assemblies: "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.7": ["System.Threading.Tasks.dll", "System.Threading.Tasks.Extensions.dll", "System.Threading.Tasks.Parallel.dll", "System.Threading.Thread.dll", "System.Threading.ThreadPool.dll", "System.Threading.Timer.dll", "System.Transactions.dll", "System.Transactions.Local.dll", "System.ValueTuple.dll", "System.Web.dll", "System.Web.HttpUtility.dll", "System.Resources.ResourceManager.dll", "System.Resources.Writer.dll", "System.Runtime.CompilerServices.Unsafe.dll", "System.Runtime.CompilerServices.VisualC.dll", "System.Runtime.dll", "System.Runtime.Extensions.dll", "System.Runtime.Handles.dll", "System.Runtime.InteropServices.dll", "System.Runtime.InteropServices.JavaScript.dll", "System.Runtime.InteropServices.RuntimeInformation.dll", "System.Runtime.Intrinsics.dll", "System.IO.Compression.ZipFile.dll", "System.IO.dll", "System.IO.FileSystem.AccessControl.dll", "System.IO.FileSystem.dll", "System.IO.FileSystem.DriveInfo.dll", "System.IO.FileSystem.Primitives.dll", "System.IO.FileSystem.Watcher.dll", "System.IO.IsolatedStorage.dll", "System.IO.MemoryMappedFiles.dll", "System.IO.Pipes.AccessControl.dll", "System.Runtime.Loader.dll", "System.Runtime.Numerics.dll", "System.Runtime.Serialization.dll", "System.Runtime.Serialization.Formatters.dll", "System.Runtime.Serialization.Json.dll", "System.Runtime.Serialization.Primitives.dll", "System.Runtime.Serialization.Xml.dll", "System.Security.AccessControl.dll", "System.Security.Claims.dll", "System.Security.Cryptography.Algorithms.dll", "System.Security.Cryptography.Cng.dll", "System.Drawing.dll", "System.Drawing.Primitives.dll", "System.Dynamic.Runtime.dll", "System.Formats.Asn1.dll", "System.Formats.Tar.dll", "System.Globalization.Calendars.dll", "System.Globalization.dll", "System.Globalization.Extensions.dll", "System.IO.Compression.Brotli.dll", "System.IO.Compression.dll", "System.IO.Compression.FileSystem.dll", "System.Private.Xml.Linq.dll", "System.Reflection.DispatchProxy.dll", "System.Reflection.dll", "System.Reflection.Emit.dll", "System.Reflection.Emit.ILGeneration.dll", "System.Reflection.Emit.Lightweight.dll", "System.Reflection.Extensions.dll", "System.Reflection.Metadata.dll", "System.Reflection.Primitives.dll", "System.Reflection.TypeExtensions.dll", "System.Resources.Reader.dll", "System.Security.Cryptography.Csp.dll", "System.Data.dll", "System.Security.Cryptography.dll", "System.Diagnostics.Contracts.dll", "System.Security.Cryptography.Encoding.dll", "System.Diagnostics.Debug.dll", "System.Security.Cryptography.OpenSsl.dll", "System.Diagnostics.DiagnosticSource.dll", "System.Security.Cryptography.Primitives.dll", "System.Diagnostics.FileVersionInfo.dll", "System.Security.Cryptography.X509Certificates.dll", "System.Diagnostics.Process.dll", "System.Security.dll", "System.Diagnostics.StackTrace.dll", "System.Security.Principal.dll", "System.Diagnostics.TextWriterTraceListener.dll", "System.Security.Principal.Windows.dll", "System.Diagnostics.Tools.dll", "System.Security.SecureString.dll", "System.Diagnostics.TraceSource.dll", "System.ServiceModel.Web.dll", "System.Diagnostics.Tracing.dll", "System.dll", "Microsoft.CSharp.dll", "Microsoft.VisualBasic.Core.dll", "Microsoft.VisualBasic.dll", "Microsoft.Win32.Primitives.dll", "Microsoft.Win32.Registry.dll", "mscorlib.dll", "netstandard.dll", "System.AppContext.dll", "System.Buffers.dll", "System.Collections.Concurrent.dll", "System.Collections.dll", "System.Collections.Immutable.dll", "System.Collections.NonGeneric.dll", "System.ServiceProcess.dll", "System.Text.Encoding.CodePages.dll", "System.Text.Encoding.dll", "System.Text.Encoding.Extensions.dll", "System.Text.Encodings.Web.dll", "System.Text.Json.dll", "System.Text.RegularExpressions.dll", "System.Threading.Channels.dll", "System.Threading.dll", "System.Threading.Overlapped.dll", "System.Threading.Tasks.Dataflow.dll", "System.Collections.Specialized.dll", "System.ComponentModel.Annotations.dll", "System.ComponentModel.DataAnnotations.dll", "System.ComponentModel.dll", "System.ComponentModel.EventBasedAsync.dll", "System.ComponentModel.Primitives.dll", "System.ComponentModel.TypeConverter.dll", "System.Configuration.dll", "System.Console.dll", "System.Core.dll", "System.Data.Common.dll", "System.Data.DataSetExtensions.dll", "System.Windows.dll", "System.Xml.dll", "System.Xml.Linq.dll", "System.Xml.ReaderWriter.dll", "System.Xml.Serialization.dll", "System.Xml.XDocument.dll", "System.Xml.XmlDocument.dll", "System.Xml.XmlSerializer.dll", "System.Xml.XPath.dll", "System.Xml.XPath.XDocument.dll", "WindowsBase.dll", "System.Net.Mail.dll", "System.Net.NameResolution.dll", "System.Net.NetworkInformation.dll", "System.Net.Ping.dll", "System.Net.Primitives.dll", "System.Net.Quic.dll", "System.Net.Requests.dll", "System.Net.Security.dll", "System.Net.ServicePoint.dll", "System.Net.Sockets.dll", "System.Net.WebClient.dll", "System.IO.Pipes.dll", "System.IO.UnmanagedMemoryStream.dll", "System.Linq.dll", "System.Linq.Expressions.dll", "System.Linq.Parallel.dll", "System.Linq.Queryable.dll", "System.Memory.dll", "System.Net.dll", "System.Net.Http.dll", "System.Net.Http.Json.dll", "System.Net.HttpListener.dll", "System.Net.WebHeaderCollection.dll", "System.Net.WebProxy.dll", "System.Net.WebSockets.Client.dll", "System.Net.WebSockets.dll", "System.Numerics.dll", "System.Numerics.Vectors.dll", "System.ObjectModel.dll", "System.Private.CoreLib.dll", "System.Private.DataContractSerialization.dll", "System.Private.Uri.dll", "System.Private.Xml.dll"]
2024-08-07T20:51:34 - MEF Default Assemblies: C:\Users\Snip\.dotnet\tools\.store\csharprepl\0.6.7\csharprepl\0.6.7\tools\net8.0\any\Microsoft.CodeAnalysis.Workspaces.dll, C:\Users\Snip\.dotnet\tools\.store\csharprepl\0.6.7\csharprepl\0.6.7\tools\net8.0\any\Microsoft.CodeAnalysis.CSharp.Workspaces.dll, C:\Users\Snip\.dotnet\tools\.store\csharprepl\0.6.7\csharprepl\0.6.7\tools\net8.0\any\Microsoft.CodeAnalysis.Features.dll, C:\Users\Snip\.dotnet\tools\.store\csharprepl\0.6.7\csharprepl\0.6.7\tools\net8.0\any\Microsoft.CodeAnalysis.CSharp.Features.dll
2024-08-07T20:51:34 - Background initialization complete
2024-08-07T20:51:34 - Warm-up Starting
2024-08-07T20:51:36 - Warm-up Complete
2024-08-07T20:51:38 - Unhandled Exception: System.ArgumentOutOfRangeException: count ('-1') must be a non-negative value. (Parameter 'count')
Actual value was -1.
   at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)
   at System.ArgumentOutOfRangeException.ThrowIfNegative[T](T value, String paramName)
   at System.String.Ctor(Char c, Int32 count)
   at CSharpRepl.PrettyPromptConfig.CSharpReplPromptCallbacks.<TransformKeyPressAsync>g__NewLineWithIndentation|14_1(Int32 indentation) in /_/CSharpRepl/CSharpReplPromptCallbacks.cs:line 175
   at CSharpRepl.PrettyPromptConfig.CSharpReplPromptCallbacks.TransformKeyPressAsync(String text, Int32 caret, KeyPress keyPress, CancellationToken cancellationToken) in /_/CSharpRepl/CSharpReplPromptCallbacks.cs:line 156
   at PrettyPrompt.Prompt.<>c__DisplayClass9_0.<<ReadLineAsync>g__InterpretKeyPress|0>d.MoveNext()
--- End of stack trace from previous location ---
   at PrettyPrompt.Prompt.ReadLineAsync()
   at CSharpRepl.ReadEvalPrintLoop.RunAsync(Configuration config) in /_/CSharpRepl/ReadEvalPrintLoop.cs:line 51
   at CSharpRepl.Program.Main(String[] args) in /_/CSharpRepl/Program.cs:line 71
   at CSharpRepl.Program.Main(String[] args) in /_/CSharpRepl/Program.cs:line 77
   at CSharpRepl.Program.<Main>(String[] args)

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions