Compiler fails to stop error print in recursive macro, and also prints unnecessary "inline at" #2513.

This commit is contained in:
Christoffer Lerno
2025-10-06 00:31:27 +02:00
parent 872f63eecc
commit e9ec421b3b
6 changed files with 45 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
### Fixes
- Bug in `io::write_using_write_byte`.
- Bitstruct value cannot be used to index a const array in compile time. #2512
- Compiler fails to stop error print in recursive macro, and also prints unnecessary "inline at" #2513.
### Stdlib changes

View File

@@ -2339,6 +2339,8 @@ static inline bool sema_analyse_compound_statement_no_scope(SemaContext *context
{
ast_poison(ast);
all_ok = false;
// Don't continue inside a macro, since we get too many "inlined" errors.
if (context->current_macro) break;
}
}
AstId *next = ast ? &ast_last(ast)->next : &compound_statement->compound_stmt.first_stmt;

View File

@@ -584,11 +584,13 @@ void sema_print_inline(SemaContext *context, SourceSpan original)
{
if (!context) return;
InliningSpan *inlined_at = context->inlined_at;
SourceSpan last_span = INVALID_SPAN;
while (inlined_at)
{
if (inlined_at->span.a != original.a)
if (inlined_at->span.a != original.a && inlined_at->span.a != last_span.a)
{
sema_note_prev_at(inlined_at->span, "Inlined from here.");
last_span = inlined_at->span;
}
inlined_at = inlined_at->prev;
}

View File

@@ -0,0 +1,12 @@
import std;
macro @_macro(#i)
{
if (#i == 0) { return; }
return @_macro(#i - 1); // #error: Failure evaluating macro, max call depth reached
}
fn void main()
{
@_macro(1);
}

View File

@@ -0,0 +1,12 @@
import std;
macro @_macro(#i)
{
if (#i == 0) { return; }
return @_macro(--#i); // #error: You cannot assign to a constant expression
}
fn void main()
{
@_macro(1);
}

View File

@@ -1,9 +1,21 @@
macro foo(...)
{
$vaarg["hello"]; // #error: Expected the argument index here
}
macro foo_a(...)
{
int x;
$vaarg[x]; // #error: Vararg functions need a constant argument
}
macro foo_b(...)
{
$vaarg[-1]; // #error: negative
}
macro foo_c(...)
{
$vaarg[100]; // #error: varargs exist
}
@@ -22,4 +34,7 @@ fn void main()
int x;
foo2(x); // #error: This argument needs to be a compile time constant
foo3(3); // #error: The argument was not a type.
foo_a(1, -1, 3141, 999 + 1);
foo_b(1, -1, 3141, 999 + 1);
foo_c(1, -1, 3141, 999 + 1);
}