gracelang / minigrace

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

Missing "{" causes unhelpful error message #268

Closed KimBruce closed 5 years ago

KimBruce commented 6 years ago

Consider the following simple program:

if (true) then
    print "OK"
} else {
    print "what?"
}

It is missing a "{" after the word "then". It generates the following very unhelpful error message:

BoundsError on line 673 of collectionsPrelude: index 0 out of bounds 1..0
  raised at Exception.raise(_) at line 673 of collectionsPrelude
  requested from list.withAll(_).boundsCheck(_) at line 673 of collectionsPrelude
  requested from list.withAll(_).at(_) at line 677 of collectionsPrelude
  requested from list.withAll(_).last at line 402 of collectionsPrelude
  requested from checkIndentationReset at line 1047 of lexer
  requested from checkIndentation(_) at line 951 of lexer
  requested from indentationState.consume(_) at line 902 of lexer
  requested from block.apply at line 1518 of lexer
  requested from while(_)do(_) at line 1497 of lexer
  requested from block.apply(_) at line 1497 of lexer
  requested from extendedLineup.do(_) at line 1495 of lexer
  requested from for(_)do(_) at line 1495 of lexer
  requested from lexInputLines at line 1495 of lexer
  requested from lexfile(_) at line 1376 of lexer
  requested from block.apply at line 20 of compiler
  requested from module initialization in compiler
  requested on line 0 of . 672:                 if ( !(n >= 1) || !(n <= size)) then { 673:                     BoundsError.raise "index {n} out of bounds 1..{size}" 674:                 }
apblack commented 6 years ago

That’s not an error message, that’s a crash.

Look at lines 1047 and 1048 of lexer.grace. There are two requests, to removeLast and last, that re not guarded by first checking that indentStack is not empty. Checks should be added; if they fail, then the lexer should raise an error along the lines of “unmatched close brace found — did you forget an opening brace?”

Andrew P Black

On 20 Aug 2018, at 17:55, Kim Bruce notifications@github.com wrote:

Consider the following simple program:

if (true) then print "OK" } else { print "what?" } It is missing a "{" after the word "then". It generates the following very unhelpful error message:

BoundsError on line 673 of collectionsPrelude: index 0 out of bounds 1..0 raised at Exception.raise() at line 673 of collectionsPrelude requested from list.withAll().boundsCheck() at line 673 of collectionsPrelude requested from list.withAll().at() at line 677 of collectionsPrelude requested from list.withAll().last at line 402 of collectionsPrelude requested from checkIndentationReset at line 1047 of lexer requested from checkIndentation() at line 951 of lexer requested from indentationState.consume() at line 902 of lexer requested from block.apply at line 1518 of lexer requested from while()do() at line 1497 of lexer requested from block.apply() at line 1497 of lexer requested from extendedLineup.do() at line 1495 of lexer requested from for()do() at line 1495 of lexer requested from lexInputLines at line 1495 of lexer requested from lexfile(_) at line 1376 of lexer requested from block.apply at line 20 of compiler requested from module initialization in compiler requested on line 0 of . 672: if ( !(n >= 1) || !(n <= size)) then { 673: BoundsError.raise "index {n} out of bounds 1..{size}" 674: } — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

KimBruce commented 6 years ago

Yes, the opening brace after “then” is missing — clearly an error, but it needed a better error message.

On Aug 21, 2018, at 10:04 AM, Andrew Black notifications@github.com wrote:

That’s not an error message, that’s a crash.

Look at lines 1047 and 1048 of lexer.grace. There are two requests, to removeLast and last, that re not guarded by first checking that indentStack is not empty. Checks should be added; if they fail, then the lexer should raise an error along the lines of “unmatched close brace found — did you forget an opening brace?”

Andrew P Black

On 20 Aug 2018, at 17:55, Kim Bruce notifications@github.com wrote:

Consider the following simple program:

if (true) then print "OK" } else { print "what?" } It is missing a "{" after the word "then". It generates the following very unhelpful error message:

BoundsError on line 673 of collectionsPrelude: index 0 out of bounds 1..0 raised at Exception.raise() at line 673 of collectionsPrelude requested from list.withAll().boundsCheck() at line 673 of collectionsPrelude requested from list.withAll().at() at line 677 of collectionsPrelude requested from list.withAll().last at line 402 of collectionsPrelude requested from checkIndentationReset at line 1047 of lexer requested from checkIndentation() at line 951 of lexer requested from indentationState.consume() at line 902 of lexer requested from block.apply at line 1518 of lexer requested from while()do() at line 1497 of lexer requested from block.apply() at line 1497 of lexer requested from extendedLineup.do() at line 1495 of lexer requested from for()do() at line 1495 of lexer requested from lexInputLines at line 1495 of lexer requested from lexfile(_) at line 1376 of lexer requested from block.apply at line 20 of compiler requested from module initialization in compiler requested on line 0 of . 672: if ( !(n >= 1) || !(n <= size)) then { 673: BoundsError.raise "index {n} out of bounds 1..{size}" 674: } — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gracelang/minigrace/issues/268#issuecomment-414748532, or mute the thread https://github.com/notifications/unsubscribe-auth/ABuh-kgJFIb2vfTYDy2q_vCw3sukEe2fks5uTD2tgaJpZM4WE7cs.

apblack commented 5 years ago

This has been fixed. The compiler highlights the closing brace on the third line, and says

Syntax error: there is no opening brace corresponding to this closing brace