Skip to content

Commit

Permalink
Ignore parser errors when other errors have already been noticed. (#2931
Browse files Browse the repository at this point in the history
)

In case we already have an error state, only count errors arising from
this parser pass.
  • Loading branch information
malthe authored and jemc committed Dec 11, 2018
1 parent 6227d31 commit b48af2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/libponyc/ast/parserapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ bool parse(ast_t* package, source_t* source, rule_t start, const char* expected,
parser->errors = errors;
parser->trace_enable = trace;

const size_t error_count = errors_get_count(errors);

// Parse given start rule
builder_fn_t build_fn;
ast_t* ast = start(parser, &build_fn, expected);
Expand All @@ -644,7 +646,7 @@ bool parse(ast_t* package, source_t* source, rule_t start, const char* expected,
ast = NULL;
}

if(errors_get_count(errors) > 0)
if(errors_get_count(errors) > error_count)
{
ast_free(ast);
ast = NULL;
Expand Down
18 changes: 9 additions & 9 deletions test/libponyc/sugar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,17 @@ TEST_F(SugarTest, FunctionNoReturnBody)

TEST_F(SugarTest, FunctionParamMustBeId)
{
const char* good =
const char* good1 =
"trait Foo\n"
" fun foo(x: U64) => 3";

TEST_COMPILE(good);
TEST_COMPILE(good1);

const char* good2 =
"trait Foo\n"
" fun foo(_: U64) => 3";

TEST_COMPILE(good2);

const char* bad1 =
"trait Foo\n"
Expand All @@ -568,16 +574,10 @@ TEST_F(SugarTest, FunctionParamMustBeId)
TEST_ERROR(bad1);

const char* bad2 =
"trait Foo\n"
" fun foo(_: U64) => 3";

TEST_ERROR(bad2);

const char* bad3 =
"trait Foo\n"
" fun foo($: U64) => 3";

TEST_ERROR(bad3);
TEST_ERROR(bad2);
}


Expand Down

0 comments on commit b48af2a

Please # to comment.