gracelang / minigrace

Self-hosting compiler for the Grace programming language
39 stars 22 forks source link

Compiler crashes when compiler file whose only content is `return` #323

Open IsaacOscar opened 4 years ago

IsaacOscar commented 4 years ago

Literally what the title says: create a grace file with body return, and mgc will crash:

BoundsError: index 5 but list has size 4
  raised from list.at(_) at /root/GraceTC/minigrace/collections.grace:423
  requested from suggestion.new.getLine(_) at /root/GraceTC/minigrace/errormessages.grace:269
  requested from suggestion.new.deleteRange(_,_)onLine(_) at /root/GraceTC/minigrace/errormessages.grace:66
  requested from suggestion.new.deleteToken(_)leading(_)trailing(_) at /root/GraceTC/minigrace/errormessages.grace:170
  requested from doreturn at /root/GraceTC/minigrace/parser.grace:2778
  requested from statement at /root/GraceTC/minigrace/parser.grace:2982
  requested from block.apply at /root/GraceTC/minigrace/parser.grace:3208
  requested from while(_)do(_) at intrinsic.grace:111
  requested from parse(_) at /root/GraceTC/minigrace/parser.grace:3184
  requested from block.apply at /root/GraceTC/minigrace/compiler.grace:39
  requested from compileInputFile at /root/GraceTC/minigrace/compiler.grace:23
  requested from module initialization at /root/GraceTC/minigrace/compiler.grace:16
 422:         method at(n) { 423:             native "js" code ‹var idx = var_n._value; 424:                 var result = this._value[idx-1];

Obviously this is such an unlikely case, it's a not a major issue. I just wanted to see if returns were allowed inside modules and what would happen.

apblack commented 4 years ago

As you can see from the backtrace, minigrace was attempting to emit an error message when it crashed. The "suggestions" logic did an index out of bounds, so you got no message.

This is one more reason to get rid of the "suggestions" logic (Issue #315)