diff --git a/cpp/src/semal.cpp b/cpp/src/semal.cpp index 3366948..e3c3b9d 100644 --- a/cpp/src/semal.cpp +++ b/cpp/src/semal.cpp @@ -201,14 +201,21 @@ namespace semal while(path.size()) { const ast::node& ancestor = tree.get(path); + const ast::node* distant_ancestor = nullptr; + if(path.size() >= 3) + { + auto distant_path = path; distant_path.pop_back(); distant_path.pop_back(); + distant_ancestor = &tree.get(distant_path); + } if(std::holds_alternative(ancestor.payload)) { - const std::string& function_name = std::get(ancestor.payload).func_name; - const function_t* found_func = this->try_find_function(function_name.c_str()); - if(found_func == nullptr) + std::string function_name = std::get(ancestor.payload).func_name; + bool is_method = distant_ancestor != nullptr && std::holds_alternative(distant_ancestor->payload); + if(is_method) { - found_func = this->try_find_function(semal::mangle_method_name(function_name)); + function_name = semal::mangle_method_name(function_name); } + const function_t* found_func = this->try_find_function(function_name.c_str()); if(found_func == nullptr) { diag::ice("at: {}: internal compiler error: found a parent function of an AST node (named \"{}\"), but could not then retrieve the function data from semantic analysis state.", ancestor.meta.to_string(), function_name); diff --git a/samples/scratchpad.psy b/samples/scratchpad.psy index e6dbfa5..cbc3c52 100644 --- a/samples/scratchpad.psy +++ b/samples/scratchpad.psy @@ -2,6 +2,7 @@ puts :: (str : i8& const) -> u0 := extern; main :: () -> i64 { puts("hello world!"); + print(); mydata : data := data{.id := 0}; mydata.print(); @@ -19,6 +20,7 @@ main :: () -> i64 ptr.increment(); ptr.print(); + print(); return 0; } @@ -41,6 +43,11 @@ data :: struct } } +print :: () -> u0 +{ + puts("free-function print!"); +} + == default : build == { set_linkage_type(executable);