From eaeafb72995ada9c9c254242836df264df3ceb9c Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 22 Sep 2025 21:11:48 +0200 Subject: [PATCH] Issue not correctly aborting compilation on recursive generics. --- releasenotes.md | 1 + src/compiler/sema_decls.c | 1 + test/test_suite/generic/recursive_generic2.c3 | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 test/test_suite/generic/recursive_generic2.c3 diff --git a/releasenotes.md b/releasenotes.md index 16e9a6ea2..7bcf63fad 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -38,6 +38,7 @@ - Taking `.ordinal` from an enum passed by pointer and then taking the address of this result would return the enum, not int. - Alias and distinct types didn't check the underlying type wasn't compile time or optional. - Incorrect nameof on nested struct names. #2492 +- Issue not correctly aborting compilation on recursive generics. ### Stdlib changes - Added generic `InterfaceList` to store a list of values that implement a specific interface diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 98c8dde76..cc7c7607f 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -5207,6 +5207,7 @@ Decl *sema_analyse_parameterized_identifier(SemaContext *c, Path *decl_path, con if (stage > ANALYSIS_POST_REGISTER) { sema_analyze_stage(instantiated_module, stage); + if (compiler.context.errors_found) return poisoned_decl; } } diff --git a/test/test_suite/generic/recursive_generic2.c3 b/test/test_suite/generic/recursive_generic2.c3 new file mode 100644 index 000000000..3109f4d2f --- /dev/null +++ b/test/test_suite/generic/recursive_generic2.c3 @@ -0,0 +1,22 @@ +module foo { Type }; + +import std::collections::list; + +struct Foo { + Type foo; + Allocator allocator; + List { Foo } children; // #error: Recursive definition of 'Foo' +} + +module test; +import std::collections::list; +import foo; + +fn int main(String[] args) +{ + Foo { int } test; + // assume we add children here but it's irrelevant for the repro + Foo {int} [] range = test.children[4:20]; + + return 0; +} \ No newline at end of file