Generic methods were incorrectly registered as functions, leading to naming collisions. #1402

This commit is contained in:
Christoffer Lerno
2024-09-04 15:13:29 +02:00
parent 63fc77a861
commit 7e47f4ed08
3 changed files with 38 additions and 1 deletions

View File

@@ -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*

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,33 @@
// #target: macos-x64
module playground::bug(<Ty>);
import std::io;
struct Foo
{
Ty x;
}
fn void Foo.print_it(&self)
{
io::printf("Method %s\n", self.x);
}
module playground::bug(<Ty>);
import std::io;
macro void print_it(...)
{
io::printn("Macro 456");
}
module playground;
import playground::bug;
def MyFoo = Foo(<int>);
fn void main(String[] args)
{
MyFoo foo = { 123 };
foo.print_it();
bug::print_it(<int>)();
}