From c2abbe2e2fb7dcaccb038f8dc0ca5c333e66bd3a Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 24 Sep 2025 00:12:58 +0200 Subject: [PATCH] Loosen generic resolution. --- src/compiler/sema_name_resolution.c | 7 ++++--- test/test_suite/generic/generic_self_ref.c3 | 2 +- test/test_suite/generic/recursive_generic.c3 | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compiler/sema_name_resolution.c b/src/compiler/sema_name_resolution.c index 70865fc48..f3453d82c 100644 --- a/src/compiler/sema_name_resolution.c +++ b/src/compiler/sema_name_resolution.c @@ -858,9 +858,10 @@ INLINE bool sema_resolve_symbol_common(SemaContext *context, NameResolve *name_r { if (found->unit->module->generic_module == context->unit->module->generic_module) { - RETURN_SEMA_ERROR_AT(name_resolve->span, "Generating a parameterized %s '%s' in the same module as the original " - "is not allowed, you need to place it outside of the '%s' module.", - str, found->name, context->unit->module->generic_module->name->module); + Decl *decl = module_find_symbol(context->unit->module->generic_module, found->name); + ASSERT(decl); + name_resolve->found = decl; + return true; } RETURN_SEMA_ERROR_AT(name_resolve->span, "This %s was matched as '%s%s' in module '%s%s', so parameterizing it further doesn't work.", str, found->name, found->unit->module->generic_suffix, found->unit->module->generic_module->name->module, found->unit->module->generic_suffix); } diff --git a/test/test_suite/generic/generic_self_ref.c3 b/test/test_suite/generic/generic_self_ref.c3 index ce56a75b4..a518375a1 100644 --- a/test/test_suite/generic/generic_self_ref.c3 +++ b/test/test_suite/generic/generic_self_ref.c3 @@ -10,7 +10,7 @@ struct Widget List {any} children; } -fn void Widget{Label}.draw(Widget* self) // #error: same module as the original is not allowed, you need to place it outside +fn void Widget{Label}.draw(Widget* self) // #error: The same method is generated by multiple instances { io::printfn("Hello Label"); } diff --git a/test/test_suite/generic/recursive_generic.c3 b/test/test_suite/generic/recursive_generic.c3 index af8ae363b..0cdf3475a 100644 --- a/test/test_suite/generic/recursive_generic.c3 +++ b/test/test_suite/generic/recursive_generic.c3 @@ -7,7 +7,7 @@ Aa {int} a; module test1 {Type}; import test2; -alias Cc = Aa {Bb {Type}}; // #error:in the same module as the original is not allowed +alias Cc = Aa {Bb {Type}}; // #error: Generic resolution of this type has become deeply nested struct Aa {Type a;} module test2 {Type};