Skip to content

Commit

Permalink
Fix compiler assert fail on circular type inference error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jemc committed Oct 22, 2016
1 parent b158d04 commit c4c7e28
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the Pony compiler and standard library will be documented
### Fixed

- Concatenate docstrings from case methods (issue #575).
- Compiler assert fail on circular type inference error (issue #1334).

### Added

Expand Down
6 changes: 3 additions & 3 deletions src/libponyc/expr/reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,6 @@ bool expr_reference(pass_opt_t* opt, ast_t** astp)

ast_t* type = ast_type(def);

if(is_typecheck_error(type))
return false;

if(type != NULL && ast_id(type) == TK_INFERTYPE)
{
ast_error(opt->check.errors, ast, "cannot infer type of %s\n",
Expand All @@ -687,6 +684,9 @@ bool expr_reference(pass_opt_t* opt, ast_t** astp)
return false;
}

if(is_typecheck_error(type))
return false;

if(!valid_reference(opt, ast, type, status))
return false;

Expand Down
17 changes: 16 additions & 1 deletion test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ TEST_F(BadPonyTest, WithBlockTypeInference)
" new create(env: Env) =>\n"
" with x = 1 do None end";

TEST_ERRORS_1(src, "could not infer literal type, no valid types found");
TEST_ERRORS_3(src, "could not infer literal type, no valid types found",
"cannot infer type of $1$0",
"cannot infer type of x");
}

TEST_F(BadPonyTest, EmbedNestedTuple)
Expand All @@ -278,3 +280,16 @@ TEST_F(BadPonyTest, EmbedNestedTuple)

TEST_ERRORS_1(src, "an embedded field must be assigned using a constructor");
}

TEST_F(BadPonyTest, CircularTypeInfer)
{
// From issue #1334
const char* src =
"actor Main\n"
" new create(env: Env) =>\n"
" let x = x.create()\n"
" let y = y.create()";

TEST_ERRORS_2(src, "cannot infer type of x",
"cannot infer type of y");
}

0 comments on commit c4c7e28

Please sign in to comment.