icy-arctic-fox / spectator

Feature-rich testing framework for Crystal inspired by RSpec.
https://gitlab.com/arctic-fox/spectator
MIT License
101 stars 4 forks source link

Noticed line/column skew during incremental porting of RSpec files over to Spectator #39

Open postmodern opened 2 years ago

postmodern commented 2 years ago

I've noticed with 0.10 that the reported line/column of compilation errors are not always accurate. I am not sure whether this is a Spectator issue or really a Crystal compiler issue. When compiling a RSpec file which has been ran through ruby_crystal_codemod and half-ported over to Crystal/Spectator, crystal spec spec/foo_spec.cr --error-trace will report a syntax error on a blank line just before another context block and a mysterious internal error. When I remove --error-trace, I can sometimes see the correct error message.

Example

Error: expanding macro

In spec/reader_spec.cr:582:1

 582 | 
       ^-------
Error: expanding macro

In spec/reader_spec.cr:621:1

 621 | 
       ^------
Error: expanding macro

In spec/reader_spec.cr:666:1

 666 | 
       ^------
Error: expanding macro

Unhandled exception: Negative argument (ArgumentError)
  from /crystal/src/string.cr:5024:13 in '*'
  from /crystal/src/compiler/crystal/exception.cr:108:7 in 'append_error_indicator'
  from /crystal/src/string/builder.cr:28:5 in 'error_body'
  from /crystal/src/compiler/crystal/semantic/exception.cr:122:10 in 'append_to_s'
  from /crystal/src/compiler/crystal/semantic/exception.cr:137:9 in 'append_to_s'
  from /crystal/src/compiler/crystal/semantic/exception.cr:137:9 in 'append_to_s'
  from /crystal/src/compiler/crystal/semantic/exception.cr:137:9 in 'append_to_s'
  from /crystal/src/compiler/crystal/semantic/exception.cr:137:9 in 'append_to_s'
  from /crystal/src/compiler/crystal/semantic/exception.cr:137:9 in 'append_to_s'
  from /crystal/src/compiler/crystal/semantic/exception.cr:137:9 in 'append_to_s'
  from /crystal/src/compiler/crystal/semantic/exception.cr:137:9 in 'append_to_s'
  from /crystal/src/compiler/crystal/semantic/exception.cr:95:7 in 'run'
  from /crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from /crystal/src/crystal/main.cr:110:5 in 'main'
  from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'
icy-arctic-fox commented 2 years ago

Yeah, I've seen this crop up from time to time. I'm not sure exactly what causes those issues.

The blank line (error pointing at the wrong source code?) might be related to an issue we've seen before that looks to be a bug in Crystal. Line numbers seem to get messed up when macros are placed in macros.

I've also seen the compiler crash and get that negative argument exception when toggling the --error-trace option. I think I've seen it caused by undefined reference to a variable or method?