Skip to content

Commit 6881f5b

Browse files
committed
Fix error() method that throws when done() is true
When done() is true last correct token and its position is printed.
1 parent 179b953 commit 6881f5b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

source/parse.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3068,15 +3068,15 @@ class parser
30683068
-> void
30693069
{
30703070
auto m = std::string{msg};
3071+
auto i = done() ? -1 : 0;
3072+
assert (peek(i));
30713073
if (include_curr_token) {
3072-
m += std::string(" (at '") + curr().to_string(true) + "')";
3074+
m += std::string(" (at '") + peek(i)->to_string(true) + "')";
30733075
}
30743076
if (
30753077
err_pos == source_position{}
3076-
&& peek(0)
3077-
)
3078-
{
3079-
err_pos = peek(0)->position();
3078+
) {
3079+
err_pos = peek(i)->position();
30803080
}
30813081
errors.emplace_back( err_pos, m, false, fallback );
30823082
}
@@ -5093,7 +5093,8 @@ class parser
50935093

50945094
// If there's no [ [ then this isn't a contract
50955095
if (
5096-
curr().type() != lexeme::LeftBracket
5096+
done()
5097+
|| curr().type() != lexeme::LeftBracket
50975098
|| !peek(1)
50985099
|| peek(1)->type() != lexeme::LeftBracket
50995100
)

0 commit comments

Comments
 (0)