Skip to content

Commit

Permalink
Correctly typecheck FFI arguments with regard to aliasing (#2550)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit Vey authored and jemc committed Feb 21, 2018
1 parent ec55c0b commit 40085d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/libponyc/expr/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../type/subtype.h"
#include "../pkg/ifdef.h"
#include "../pass/expr.h"
#include "../type/alias.h"
#include "ponyassert.h"
#include <string.h>

Expand Down Expand Up @@ -54,29 +55,32 @@ static bool declared_ffi(pass_opt_t* opt, ast_t* call, ast_t* decl)
if(!coerce_literals(&arg, p_type, opt))
return false;

ast_t* a_type = ast_type(arg);
ast_t* arg_type = ast_type(arg);

if (is_typecheck_error(a_type))
if(is_typecheck_error(arg_type))
return false;

if(ast_id(a_type) == TK_TUPLETYPE)
if(ast_id(arg_type) == TK_TUPLETYPE)
{
ast_error(opt->check.errors, arg, "cannot pass tuples as FFI arguments");
return false;
}

ast_t* a_type = alias(arg_type);
errorframe_t info = NULL;
if((a_type != NULL) &&
!void_star_param(p_type, a_type) &&

if(!void_star_param(p_type, a_type) &&
!is_subtype(a_type, p_type, &info, opt))
{
errorframe_t frame = NULL;
ast_error_frame(&frame, arg, "argument not a subtype of parameter");
errorframe_append(&frame, &info);
errorframe_report(&frame, opt->check.errors);
ast_free_unattached(a_type);
return false;
}

ast_free_unattached(a_type);
arg = ast_sibling(arg);
param = ast_sibling(param);
}
Expand Down
14 changes: 14 additions & 0 deletions test/libponyc/ffi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,17 @@ TEST_F(FFITest, DeclarationEllipsisNotLast)

TEST_ERROR(src);
}


TEST_F(FFITest, DeclarationAlias)
{
const char* src =
"use @foo[None](x: Foo iso)\n"

"class Foo\n"
" fun f() =>\n"
" let x: Foo iso = Foo\n"
" @foo(x)";

TEST_ERROR(src);
}

0 comments on commit 40085d2

Please sign in to comment.