1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-12 19:22:37 +00:00

[FunC] Produce an error on get methods hash (method_id) collision

This commit is contained in:
Aleksandr Kirsanov 2024-05-21 17:50:06 +03:00
parent 7b8268d99f
commit 8932c515c9
No known key found for this signature in database
GPG key ID: B758BBAA01FFB3D3
4 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,15 @@
get int secret() pure {
return 0;
}
get int balanced() pure {
return 1;
}
int main() {
return secret() + balanced();
}
{-
@compilation_should_fail
@stderr GET methods hash collision: `secret` and `balanced` produce the same hash
-}

View file

@ -28,7 +28,7 @@ using namespace std::literals::string_literals;
*/
int glob_func_cnt, undef_func_cnt, glob_var_cnt, const_cnt;
std::vector<SymDef*> glob_func, glob_vars;
std::vector<SymDef*> glob_func, glob_vars, glob_get_methods;
std::set<std::string> prohibited_var_names;
SymDef* define_builtin_func_impl(const std::string& name, SymValAsmFunc* func_val) {

View file

@ -874,7 +874,7 @@ struct SymValConst : sym::SymValBase {
};
extern int glob_func_cnt, undef_func_cnt, glob_var_cnt;
extern std::vector<SymDef*> glob_func, glob_vars;
extern std::vector<SymDef*> glob_func, glob_vars, glob_get_methods;
extern std::set<std::string> prohibited_var_names;
/*

View file

@ -1579,6 +1579,11 @@ void parse_func_def(Lexer& lex) {
if (is_get_method) {
func_assert(method_id.is_null());
method_id = calculate_method_id_by_func_name(func_name.str);
for (const SymDef* other : glob_get_methods) {
if (!td::cmp(dynamic_cast<const SymValFunc*>(other->value)->method_id, method_id)) {
lex.cur().error(PSTRING() << "GET methods hash collision: `" << other->name() << "` and `" + func_name.str + "` produce the same hash. Consider renaming one of these functions.");
}
}
}
TypeExpr* func_type = TypeExpr::new_map(extract_total_arg_type(arg_list), ret_type);
func_type = compute_type_closure(func_type, type_vars);
@ -1698,6 +1703,7 @@ void parse_func_def(Lexer& lex) {
lex.cur().error("cannot set unknown function `"s + func_name.str + "` as a get method");
}
val->flags |= SymValFunc::flagGetMethod;
glob_get_methods.push_back(func_sym);
}
if (verbosity >= 1) {
std::cerr << "new type of function " << func_name.str << " : " << func_type << std::endl;