mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Compiler fails to stop error print in recursive macro, and also prints unnecessary "inline at" #2513.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
12
test/test_suite/macros/macro_recursive_err.c3
Normal file
12
test/test_suite/macros/macro_recursive_err.c3
Normal 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);
|
||||
}
|
||||
12
test/test_suite/macros/macro_recursive_err2.c3
Normal file
12
test/test_suite/macros/macro_recursive_err2.c3
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user