From 7e47f4ed08b452b22430c4ee969b7438e24bc768 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 4 Sep 2024 15:13:29 +0200 Subject: [PATCH] Generic methods were incorrectly registered as functions, leading to naming collisions. #1402 --- releasenotes.md | 1 + src/compiler/semantic_analyser.c | 5 ++- .../generic/generic_resolution_1402.c3t | 33 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/generic/generic_resolution_1402.c3t diff --git a/releasenotes.md b/releasenotes.md index 4da027703..15ccd00fd 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -7,6 +7,7 @@ ### Fixes - Issue where a lambda wasn't correctly registered as external. #1408 +- Generic methods were incorrectly registered as functions, leading to naming collisions. #1402 ### Stdlib changes *None yet* diff --git a/src/compiler/semantic_analyser.c b/src/compiler/semantic_analyser.c index 894e2098b..e89ff86ab 100644 --- a/src/compiler/semantic_analyser.c +++ b/src/compiler/semantic_analyser.c @@ -230,7 +230,10 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls) break; } htable_set(&unit->module->symbols, (void *)decl->name, decl); - if (decl->visibility == VISIBLE_PUBLIC) global_context_add_generic_decl(decl); + if (decl->visibility == VISIBLE_PUBLIC && decl->decl_kind != DECL_MACRO) + { + global_context_add_generic_decl(decl); + } } } diff --git a/test/test_suite/generic/generic_resolution_1402.c3t b/test/test_suite/generic/generic_resolution_1402.c3t new file mode 100644 index 000000000..3d6a7d668 --- /dev/null +++ b/test/test_suite/generic/generic_resolution_1402.c3t @@ -0,0 +1,33 @@ +// #target: macos-x64 +module playground::bug(); +import std::io; + +struct Foo +{ + Ty x; +} + +fn void Foo.print_it(&self) +{ + io::printf("Method %s\n", self.x); +} + +module playground::bug(); +import std::io; + +macro void print_it(...) +{ + io::printn("Macro 456"); +} + +module playground; +import playground::bug; + +def MyFoo = Foo(); + +fn void main(String[] args) +{ + MyFoo foo = { 123 }; + foo.print_it(); + bug::print_it()(); +} \ No newline at end of file