Crystal 0.24.1, mac osx
With this code:
def foo
[1][2]
end
foo
I get this output:
Index out of bounds (IndexError)
from src/indexable.cr:0:17 in 'at'
from src/indexable.cr:73:5 in '[]'
from foo.cr:2:3 in 'foo'
from foo.cr:5:1 in '__crystal_main'
from src/crystal/main.cr:11:3 in '_crystal_main'
from src/crystal/main.cr:112:5 in 'main_user_code'
from src/crystal/main.cr:101:7 in 'main'
from src/crystal/main.cr:141:3 in 'main'
Note this line:
from src/indexable.cr:0:17 in 'at'
It has line 0, column 17. It's not correct.
I checked the .ll file produced by this program and I couldn't find any line: 0 in it (plus I debugged the compiler and it didn't happen either), which might mean the dwarf parser has a bug or something is missing.
I didn't try this on linux to see if it happens there too.
/cc @ysbaddaden (in case you are interested in investigating this)
It would be interesting to see what gdb or lldb decodes.
The same backtrace, usually.
Please create a separate issue @Wulfklaue, thanks. This isn't a mailing list nor a forum, but a bug tracker.
I wonder if #5470 is related to this. I assumed that was specific to using $0, but maybe it's an example of a more general problem. I need to go back to that and see if I can come up with a minimal version.
Reproducible on Linux.
DWARF decoding seems correct. A program such as readelf --debug-dump=line .build/crystal will exhibit there there are recordings of address:file:line in the matrix where the line is indeed 0. See for example the following, where a special opcode means updating both the address (pc) and line and record to the matrix; many lines are set to zero:
[0x0000077d] Set File Name to entry 10 in the File Name Table
[0x0000077f] Set column to 1
[0x00000781] Advance Line by -320 to 1
[0x00000784] Advance PC by constant 17 to 0x71d59e
[0x00000785] Special opcode 5: advance Address by 0 to 0x71d59e and Line by 0 to 1
[0x00000786] Set is_stmt to 0
[0x00000787] Special opcode 102: advance Address by 7 to 0x71d5a5 and Line by -1 to 0
[0x00000788] Advance PC by 38 to 0x71d5cb
[0x0000078a] Special opcode 6: advance Address by 0 to 0x71d5cb and Line by 1 to 1
[0x0000078b] Special opcode 144: advance Address by 10 to 0x71d5d5 and Line by -1 to 0
[0x0000078c] Set File Name to entry 11 in the File Name Table
[0x0000078e] Special opcode 104: advance Address by 7 to 0x71d5dc and Line by 1 to 1
[0x0000078f] Special opcode 102: advance Address by 7 to 0x71d5e3 and Line by -1 to 0
The backtrace I'm getting now is:
Unhandled exception: Index out of bounds (IndexError)
from /usr/local/Cellar/crystal/0.25.1/src/indexable.cr:596:8 in 'at'
from /usr/local/Cellar/crystal/0.25.1/src/indexable.cr:73:5 in '[]'
from foo.cr:2:3 in 'foo'
from foo.cr:5:1 in '__crystal_main'
from /usr/local/Cellar/crystal/0.25.1/src/crystal/main.cr:104:5 in 'main_user_code'
from /usr/local/Cellar/crystal/0.25.1/src/crystal/main.cr:93:7 in 'main'
from /usr/local/Cellar/crystal/0.25.1/src/crystal/main.cr:133:3 in 'main'
which is almost correct: the error happens at line 591, not 596. But at least it's not 0 anymore :-P
Oh, cool ?
In Crystal 0.31.1 it's no longer points to line 0
def foo
[1][2]
end
foo
It points to the correct location https://github.com/crystal-lang/crystal/blob/0.31.1/src/indexable.cr#L73
$ crystal e.cr
Unhandled exception: Index out of bounds (IndexError)
from /usr/local/Cellar/crystal/0.31.1/src/indexable.cr:73:20 in '[]'
from e.cr:2:3 in 'foo'
from e.cr:5:1 in '__crystal_main'
from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:97:5 in 'main_user_code'
from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:86:7 in 'main'
from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:106:3 in 'main'
$ crystal --version
Crystal 0.31.1 (2019-10-02)
LLVM: 8.0.1
Default target: x86_64-apple-macosx
Probably fixed by #8234