From f69bffc2c7619e3355793454e1ddb202a66e363c Mon Sep 17 00:00:00 2001 From: Igor Deepak <117689228+IgorDeepakM@users.noreply.github.com> Date: Wed, 13 May 2026 23:22:24 +0200 Subject: [PATCH] Add reserved member name for methods and embed Forgot to add checks against using reserved member names for methods and embed variables. Added checks for those as well. --- src/libponyc/pass/syntax.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libponyc/pass/syntax.c b/src/libponyc/pass/syntax.c index 30dc16a17..a56d35c7c 100644 --- a/src/libponyc/pass/syntax.c +++ b/src/libponyc/pass/syntax.c @@ -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) { @@ -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; @@ -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); @@ -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; }