Skip to content

Commit

Permalink
Reify function references used as addressof operands correctly (#1857)
Browse files Browse the repository at this point in the history
Previously, a function reference used as the operand of `addressof` was
only reified in `expr_qualify`. Since this function is only called when
there is at least one type argument, a function referenced with no type
arguments wouldn't be checked. This change fixes the issue by reifying
the function in `expr_addressof` if the function reference wasn't
already reified.
  • Loading branch information
Benoit Vey authored and jemc committed Apr 21, 2017
1 parent 6f0bac8 commit 98e92b3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 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

- Properly account for foreign objects in GC ([PR #1842](https://github.com/ponylang/ponyc/pull/1842))
- Compiler crash when using the `addressof` operator on a function with an incorrect number of type arguments

### Added

Expand Down
4 changes: 2 additions & 2 deletions src/libponyc/expr/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static bool insert_apply(pass_opt_t* opt, ast_t** astp)
return expr_call(opt, astp);
}

static bool check_type_params(pass_opt_t* opt, ast_t** astp)
bool method_check_type_params(pass_opt_t* opt, ast_t** astp)
{
ast_t* lhs = *astp;
ast_t* type = ast_type(lhs);
Expand Down Expand Up @@ -488,7 +488,7 @@ static bool method_application(pass_opt_t* opt, ast_t* ast, bool partial)
{
AST_GET_CHILDREN(ast, positional, namedargs, lhs);

if(!check_type_params(opt, &lhs))
if(!method_check_type_params(opt, &lhs))
return false;

ast_t* type = ast_type(lhs);
Expand Down
2 changes: 2 additions & 0 deletions src/libponyc/expr/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

PONY_EXTERN_C_BEGIN

bool method_check_type_params(pass_opt_t* opt, ast_t** astp);

bool expr_call(pass_opt_t* opt, ast_t** astp);

PONY_EXTERN_C_END
Expand Down
3 changes: 3 additions & 0 deletions src/libponyc/expr/reference.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ bool expr_addressof(pass_opt_t* opt, ast_t* ast)
{
case TK_FUNREF:
case TK_BEREF:
if(!method_check_type_params(opt, &expr))
return false;

expr_type = type_builtin(opt, ast, "None");
break;

Expand Down
14 changes: 14 additions & 0 deletions test/libponyc/badpony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,17 @@ TEST_F(BadPonyTest, ObjectInheritsLaterTraitMethodWithParameter)

TEST_COMPILE(src);
}


TEST_F(BadPonyTest, AddressofMissingTypearg)
{
const char* src =
"actor Main\n"
" new create(env: Env) =>\n"
" @foo[None](addressof fn)\n"

" fun fn[A]() => None";

TEST_ERRORS_1(src,
"not enough type arguments");
}

0 comments on commit 98e92b3

Please sign in to comment.