Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/libponyc/pass/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ static bool check_permission(pass_opt_t* opt, const permission_def_t* def,
}


static bool is_reserved_member_name(const char* name)
{
if(name == stringtab("size_of") || name == stringtab("offset_of"))
{
return true;
}

return false;
}


// Check whether the given method has any illegal parts
static bool check_method(pass_opt_t* opt, ast_t* ast, int method_def_index)
{
Expand Down Expand Up @@ -257,6 +268,14 @@ static bool check_method(pass_opt_t* opt, ast_t* ast, int method_def_index)
r = false;
}

const char* name = ast_name(id);
if(is_reserved_member_name(name))
{
ast_error(opt->check.errors, ast, "cannot name a method, constructor or a behaviour '%s' "
"because it is a reserved name", ast_name(id));
r = false;
}

if(!check_id_method(opt, id))
r = false;

Expand Down Expand Up @@ -936,7 +955,7 @@ static ast_result_t syntax_local(pass_opt_t* opt, ast_t* ast)
static ast_result_t syntax_fvar_flet(pass_opt_t* opt, ast_t* ast)
{
const char* name = ast_name(ast_child(ast));
if(name == stringtab("size_of") || name == stringtab("offset_of"))
if(is_reserved_member_name(name))
{
ast_error(opt->check.errors, ast, "cannot name a field variable '%s' "
"because it is a reserved name", name);
Expand All @@ -955,6 +974,14 @@ static ast_result_t syntax_embed(pass_opt_t* opt, ast_t* ast)
return AST_ERROR;
}

const char* name = ast_name(ast_child(ast));
if(is_reserved_member_name(name))
{
ast_error(opt->check.errors, ast, "cannot name an embedded field variable '%s' "
"because it is a reserved name", name);
return AST_ERROR;
}

return AST_OK;
}

Expand Down
Loading