- Correctly errors when a generic module contains a self-generic type.

This commit is contained in:
Christoffer Lerno
2025-03-26 18:04:00 +01:00
parent e0f1919849
commit 4538a1f50d
4 changed files with 37 additions and 0 deletions

View File

@@ -60,6 +60,7 @@
- Incorrectly allowed getting pointer to a macro #2049.
- &self not runtime null-checked in macro #1827.
- Bug when printing a boolean value as an integer using printf.
- Show error when a generic module contains a self-generic type.
### Stdlib changes
- `new_*` functions in general moved to version without `new_` prefix.

View File

@@ -4497,6 +4497,13 @@ Decl *sema_analyse_parameterized_identifier(SemaContext *c, Path *decl_path, con
Decl *alias = name_resolve.found;
ASSERT(alias);
Module *module = alias->unit->module;
if (c->unit->module->generic_module == module)
{
sema_error_at(c, span, "This identifier is recursively using %s.", module->name->module);
return poisoned_decl;
}
unsigned parameter_count = vec_size(module->parameters);
ASSERT(parameter_count > 0);
if (parameter_count != vec_size(params))

View File

@@ -0,0 +1,29 @@
module gui::widget {Type};
import gui::widget_types;
import std::collections::list;
import std::io;
struct Widget
{
int id;
Type type;
List {any} children;
}
fn void Widget{Label}.draw(Widget* self) // #error: This identifier is recursively using gui::widget
{
io::printfn("Hello Label");
}
module gui::widget_types;
import gui::widget;
struct Label
{
String text;
}
fn void main()
{
Widget {int} y;
y.draw();
}