rsdn/nitra

Too many unindents cause ArgumentOutOfRangeException when pretty-printing

ssrmm opened this issue · 0 comments

ssrmm commented

The following code produces System.ArgumentOutOfRangeException during pretty-printing:

namespace Test
{
  syntax module TestSyntax
  {
    using Nitra.Core;

    [StartRule]
    syntax Foo = "foo" nl '{' inl "bar" nl d d '}'; 
  } //            Too many decrements here --^
}
System.ArgumentOutOfRangeException: Count cannot be less than zero
Parameter name: repeatCount
   at System.Text.StringBuilder.Append(Char value, Int32 repeatCount)
   at Nitra.StringPrettyPrintWriter.IndentCurrentLine() in D:\<...>\Nitra\Nitra\Nitra.Runtime\PrettyPrint\StringPrettyPrintWriter.n:Line 178.
   at Nitra.StringPrettyPrintWriter.Unindent() in D:\<...>\Nitra\Nitra\Nitra.Runtime\PrettyPrint\StringPrettyPrintWriter.n:Line 151.
   at Test.TestSyntaxParseTree.Foo.PrettyPrint(PrettyPrintWriter writer, Int32 callerBindingPower, SpanClass spanClass) in C:\Users\<...>\AppData\Local\Temp\_N_GeneratedSource_BugTests.n:Line 473.
   at Nitra.ParseTree.ToString(PrettyPrintOptions options) in D:\<...>\Nitra\Nitra\Nitra.Runtime\ParseTree\ParseTree.n:Line 45.
   at Nitra.ParseTree.ToString() in D:\<...>\Nitra\Nitra\Nitra.Runtime\ParseTree\ParseTree.n:Line 32.
   at System.String.Concat(Object arg0, Object arg1)
   at TestApp.Program.Main(String[] args) in d:\<...>\Program.cs:Line 31.

Ideally this would be a compile time error instead.