gracelang / minigrace

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

Compiler crash on error #330

Closed KimBruce closed 4 years ago

KimBruce commented 4 years ago

The following incorrect program omits a final closing "{"

method brighten -> Done {
  def lighten: Number = 100
  def newRed: Number = if (true) then { print "hi"} else {
       print "there"
  }

It generates the following error message in the browser version:

Internal compiler error at line 423 of collections. BoundsError: index 6 but list has size 5
BoundsError: index 6 but list has size 5
  raised from list.at(_) at line 423 of collections
  requested from suggestion.new.getLine(_) at line 272 of errormessages
  requested from suggestion.new.deleteRange(_,_)onLine(_) at line 69 of errormessages
  requested from suggestion.new.deleteToken(_)leading(_)trailing(_) at line 173 of errormessages
  requested from suggestion.new.deleteToken(_) at line 177 of errormessages
  requested from methodDeclaration(_) at line 2507 of parser
  requested from methodClassOrTrait at line 2467 of parser
  requested from block.apply at line 3280 of parser
  requested from while(_)do(_) at line 113 of intrinsic
  requested from parse(_) at line 3277 of parser
  requested from block.apply at line 39 of compiler
  requested from compileInputFile at line 23 of compiler
Compilation terminated.
    in "minigrace"
apblack commented 4 years ago

It’s that blasted suggestions mechanism again!

Andrew

On 26 Nov 2020, at 15:27, Kim Bruce notifications@github.com wrote:

The following incorrect program omits a final closing "{"

method brighten -> Done { def lighten: Number = 100 def newRed: Number = if (true) then { print "hi"} else { print "there" } It generates the following error message in the browser version:

Internal compiler error at line 423 of collections. BoundsError: index 6 but list has size 5 BoundsError: index 6 but list has size 5 raised from list.at() at line 423 of collections requested from suggestion.new.getLine() at line 272 of errormessages requested from suggestion.new.deleteRange(,)onLine() at line 69 of errormessages requested from suggestion.new.deleteToken()leading()trailing() at line 173 of errormessages requested from suggestion.new.deleteToken() at line 177 of errormessages requested from methodDeclaration() at line 2507 of parser requested from methodClassOrTrait at line 2467 of parser requested from block.apply at line 3280 of parser requested from while()do() at line 113 of intrinsic requested from parse(_) at line 3277 of parser requested from block.apply at line 39 of compiler requested from compileInputFile at line 23 of compiler Compilation terminated. in "minigrace" — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gracelang/minigrace/issues/330, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADEKDPRGDWS5AQHZR34OHTSR3P6RANCNFSM4UEH4UNA.

apblack commented 4 years ago

I hacked at findClosingBrace(_, _) which was returning the wrong result. However, lack of tests and a loosely-written specification leave it unclear what result is intended. This change is in commit e2fa6085457 (minigrace version 5054)

The above example now produces a reasonable message:

Syntax error: end of program found while searching for the '}' to close a method declaration.
    in "brighten" (line 6, column 3)