crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.45k stars 1.62k forks source link

docs: Negative count: -70 (ArgumentError) #11323

Closed GeopJr closed 3 years ago

GeopJr commented 3 years ago

Using crystal docs on https://github.com/GeopJr/libadwaita.cr, exits with the following (and without finishing generating the docs of course):

Error

Negative count: -70 (ArgumentError)
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from __crystal_main
  from main
  from __libc_start_main
  from _start
  from ???
Error: you've found a bug in the Crystal compiler.

Environment

Shards 0.16.0 (2021-10-14)
Crystal 1.2.0 (2021-10-14)

LLVM: 12.0.1
Default target: x86_64-pc-linux-gnu

Reproduction

This doesn't happen on version 1.1.1

straight-shoota commented 3 years ago

According to the stack trace, the error appears to be inside markd (which Crystal 1.1.1 didn't use).

Negative count: -70 (ArgumentError)
  from /home/johannes/Projects/crystal-lang/crystal/src/indexable.cr:921:5 in 'byte_slice?'
  from /home/johannes/Projects/crystal-lang/crystal/src/string.cr:1154:5 in 'byte_slice'
  from /home/johannes/Projects/crystal-lang/crystal/lib/markd/src/markd/parsers/inline.cr:229:44 in 'close_bracket'
  from /home/johannes/Projects/crystal-lang/crystal/lib/markd/src/markd/parsers/inline.cr:52:15 in 'process_line'
  from /home/johannes/Projects/crystal-lang/crystal/lib/markd/src/markd/parsers/inline.cr:24:22 in 'parse'
  from /home/johannes/Projects/crystal-lang/crystal/lib/markd/src/markd/parsers/block.cr:198:11 in 'process_inlines'
  from /home/johannes/Projects/crystal-lang/crystal/lib/markd/src/markd/parsers/block.cr:59:9 in 'parse'
  from /home/johannes/Projects/crystal-lang/crystal/lib/markd/src/markd/parsers/block.cr:6:7 in 'parse'
  from /home/johannes/Projects/crystal-lang/crystal/lib/markd/src/markd/parser.cr:4:7 in 'parse'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/generator.cr:321:5 in 'render_markdown'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/generator.cr:315:5 in 'doc'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/generator.cr:305:5 in 'doc'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/item.cr:3:5 in 'formatted_doc'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/html/type.html:30:7 in 'to_s'
  from /home/johannes/Projects/crystal-lang/crystal/src/io.cr:174:5 in '<<'
  from /home/johannes/Projects/crystal-lang/crystal/src/io.cr:188:5 in 'print'
  from /home/johannes/Projects/crystal-lang/crystal/src/file.cr:717:9 in 'write'
  from /home/johannes/Projects/crystal-lang/crystal/src/file.cr:709:3 in 'write'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/generator.cr:118:7 in 'generate_types_docs'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/generator.cr:124:9 in 'generate_types_docs'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/generator.cr:78:5 in 'generate_docs_html'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/tools/doc/generator.cr:46:7 in 'run'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/command/docs.cr:141:5 in 'docs'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/command.cr:90:7 in 'run'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/command.cr:49:5 in 'run'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal/command.cr:48:3 in 'run'
  from /home/johannes/Projects/crystal-lang/crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from /home/johannes/Projects/crystal-lang/crystal/src/crystal/main.cr:110:5 in 'main_user_code'
  from /home/johannes/Projects/crystal-lang/crystal/src/crystal/main.cr:96:7 in 'main'
  from /home/johannes/Projects/crystal-lang/crystal/src/crystal/main.cr:119:3 in 'main'
  from __libc_start_main
  from _start
  from ???

This is the current value of @text when the error occurs:

https://github.com/GeopJr/libadwaita.cr/blob/d397a7bb5f6c922d8cd98d844ef5e7b190d4cbca/src/auto/gio-2.0/application_command_line.cr#L147-L154

start_pos is 13 and opener.index is 83, which results in a negative difference.

A quick fix is to avoid the exception by checking if the slice size is negative. ref_label would stay nil in that case, and it allows the doc generator to complete.

/cc @icyleaf Any ideas?

straight-shoota commented 3 years ago

...and it's already been fixed: https://github.com/icyleaf/markd/pull/43 Thanks @icyleaf!

I'll pull in the upstream changes.

icyleaf commented 3 years ago

markd 0.4.2 was out.