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

[FunC] Forbid auto-creating undefined symbols

This commit is contained in:
Aleksandr Kirsanov 2024-05-02 20:54:07 +03:00
parent 4994ae8edd
commit f217a7d312
No known key found for this signature in database
GPG key ID: B758BBAA01FFB3D3
7 changed files with 40 additions and 16 deletions

View file

@ -28,7 +28,8 @@
["jetton-minter/jetton-minter.fc", 9028309926287301331466371999814928201427184114165428257502393474125007156494]
["gg-marketplace/nft-marketplace-v2.fc", 92199806964112524639740773542356508485601908152150843819273107618799016205930]
["jetton-wallet/jetton-wallet.fc", 86251125787443633057458168028617933212663498001665054651523310772884328206542]
["whales-nominators/nominators.fc", 8941364499854379927692172316865293429893094891593442801401542636695127885153]
// (May 2024) reordered includes, they were in a wrong order
["whales-nominators/nominators.fc", 64989185004203073400683226767264384908045055609681310145961012819587514238303]
// (April 2024) tact hashes changed, because '__tact_address_eq()' is now inlined as a wrapper

View file

@ -8,8 +8,8 @@
#include "modules/store-validator.fc";
#include "modules/model.fc";
#include "modules/op-controller.fc";
#include "modules/op-owner.fc";
#include "modules/op-common.fc";
#include "modules/op-owner.fc";
#include "modules/op-nominators.fc";
#include "modules/get.fc";

View file

@ -0,0 +1,12 @@
int main(int x) {
return 1 + demo();
}
int demo() {
return 2;
}
{-
@compilation_should_fail
@stderr undefined symbol `demo`
-}

View file

@ -0,0 +1,10 @@
int main(int x) {
return 1 + demo;
}
global int demo;
{-
@compilation_should_fail
@stderr undefined symbol `demo`
-}

View file

@ -0,0 +1,10 @@
int demo(int x);
int main(int x) {
return 1 + demo(x);
}
{-
@compilation_should_fail
@stderr function `demo` is just declared, not implemented
-}

View file

@ -107,8 +107,7 @@ void generate_output_func(SymDef* func_sym, std::ostream &outs, std::ostream &er
errs << "\n\n=========================\nfunction " << name << " : " << func_val->get_type() << std::endl;
}
if (!func_val->code) {
errs << "( function `" << name << "` undefined )\n";
throw src::ParseError(func_sym->loc, name);
throw src::ParseError(func_sym->loc, "function `" + name + "` is just declared, not implemented");
} else {
CodeBlob& code = *(func_val->code);
if (verbosity >= 3) {

View file

@ -396,19 +396,11 @@ SymValCodeFunc* make_new_glob_func(SymDef* func_sym, TypeExpr* func_type, bool i
return res;
}
bool check_global_func(const Lexem& cur, sym_idx_t func_name = 0) {
if (!func_name) {
func_name = cur.val;
}
bool check_global_func(const Lexem& cur, sym_idx_t func_name) {
SymDef* def = sym::lookup_symbol(func_name);
if (!def) {
cur.loc.show_error(std::string{"undefined function `"} + symbols.get_name(func_name) +
"`, defining a global function of unknown type");
def = sym::define_global_symbol(func_name, 0, cur.loc);
func_assert(def && "cannot define global function");
++undef_func_cnt;
make_new_glob_func(def, TypeExpr::new_func()); // was: ... ::new_func()
return true;
cur.error("undefined symbol `" + symbols.get_name(func_name) + "`");
return false;
}
SymVal* val = dynamic_cast<SymVal*>(def->value);
if (!val) {
@ -652,7 +644,7 @@ Expr* parse_expr100(Lexer& lex, CodeBlob& code, bool nv) {
// std::cerr << "defined new variable " << lex.cur().str << " : " << res->e_type << std::endl;
} else {
if (!sym) {
check_global_func(lex.cur());
check_global_func(lex.cur(), lex.cur().val);
sym = sym::lookup_symbol(lex.cur().val);
}
res->sym = sym;