diff --git a/releasenotes.md b/releasenotes.md index ccd7c58c8..afead88ea 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -82,6 +82,7 @@ - Bug when compile time subtracting a distinct type. - `insert_at` incorrectly prevented inserts at the end of a list. - Fix aligned alloc for Win32 targets. +- Compiler didn't detect when a module name was used both as a generic and regular module. ### Stdlib changes diff --git a/src/compiler/context.c b/src/compiler/context.c index 4c5898b5b..2a740be7e 100644 --- a/src/compiler/context.c +++ b/src/compiler/context.c @@ -20,6 +20,13 @@ static inline bool create_module_or_check_name(CompilationUnit *unit, Path *modu if (!module) { module = unit->module = compiler_find_or_create_module(module_name, parameters); + if ((parameters == NULL) == module->is_generic) + { + print_error_at(module_name->span, "'%s' is both used as regular and generic module, it can't be both.", + module_name->module); + SEMA_NOTE(module->name, "The definition here is different."); + return false; + } } else { diff --git a/test/test_suite/module/module_generic_mixing.c3 b/test/test_suite/module/module_generic_mixing.c3 new file mode 100644 index 000000000..be62be825 --- /dev/null +++ b/test/test_suite/module/module_generic_mixing.c3 @@ -0,0 +1,7 @@ +module test; +fn void main() {} + +module test(); // #error: generic +fn void test() { + Type a; +} \ No newline at end of file diff --git a/test/test_suite/switch/switch_in_defer_macro.c3t b/test/test_suite/switch/switch_in_defer_macro.c3t index f18dfe396..1f122f2f2 100644 --- a/test/test_suite/switch/switch_in_defer_macro.c3t +++ b/test/test_suite/switch/switch_in_defer_macro.c3t @@ -454,7 +454,7 @@ fn void! lex_uint() assert(kind == UINT, "got %s; want %s", kind, Kind.UINT); } } -module lexer; +module lexer2; import std::io; fn int main(String[] args)