mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Error when using $vaarg/$vacount/$vasplat and similar in a macro without vaargs #2510.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
## 0.7.7 Change list
|
||||
|
||||
### Changes / improvements
|
||||
- Error when using $vaarg/$vacount/$vasplat and similar in a macro without vaargs #2510.
|
||||
|
||||
### Fixes
|
||||
- Bug in `io::write_using_write_byte`.
|
||||
|
||||
@@ -1800,6 +1800,7 @@ struct SemaContext_
|
||||
Type *expected_block_type;
|
||||
Ast **block_returns;
|
||||
Expr **macro_varargs;
|
||||
bool macro_has_vaargs;
|
||||
Decl **macro_params;
|
||||
bool macro_has_ensures;
|
||||
Decl** ct_locals;
|
||||
|
||||
@@ -2695,7 +2695,8 @@ static inline bool sema_expr_setup_call_analysis(SemaContext *context, CalledDec
|
||||
expr->expr_other_context.inner = expr_inner;
|
||||
expr->expr_other_context.context = context;
|
||||
}
|
||||
macro_context->macro_varargs = callee->macro && callee->signature->variadic == VARIADIC_RAW ? call_expr->call_expr.varargs : NULL;
|
||||
macro_context->macro_has_vaargs = callee->macro && callee->signature->variadic == VARIADIC_RAW;
|
||||
macro_context->macro_varargs = macro_context->macro_has_vaargs ? call_expr->call_expr.varargs : NULL;
|
||||
macro_context->original_inline_line = context->original_inline_line ? context->original_inline_line : call_expr->span.row;
|
||||
macro_context->original_module = context->original_module ? context->original_module : context->compilation_unit->module;
|
||||
macro_context->macro_params = params;
|
||||
@@ -10986,9 +10987,9 @@ static inline bool sema_expr_analyse_ct_arg(SemaContext *context, Type *infer_ty
|
||||
{
|
||||
ASSERT_SPAN(expr, expr->resolve_status == RESOLVE_RUNNING);
|
||||
TokenType type = expr->ct_arg_expr.type;
|
||||
if (!context->current_macro)
|
||||
if (!context->macro_has_vaargs)
|
||||
{
|
||||
RETURN_SEMA_ERROR(expr, "'%s' can only be used inside of a macro.", token_type_to_string(type));
|
||||
RETURN_SEMA_ERROR(expr, "'%s' can only be used inside of a macro with untyped vaargs.", token_type_to_string(type));
|
||||
}
|
||||
switch (type)
|
||||
{
|
||||
|
||||
@@ -403,9 +403,9 @@ INLINE bool sema_resolve_typefrom(SemaContext *context, TypeInfo *type_info, Res
|
||||
// $vatype(...)
|
||||
INLINE bool sema_resolve_vatype(SemaContext *context, TypeInfo *type_info)
|
||||
{
|
||||
if (!context->current_macro)
|
||||
if (!context->macro_has_vaargs)
|
||||
{
|
||||
RETURN_SEMA_ERROR(type_info, "'%s' can only be used inside of a macro.", token_type_to_string(TOKEN_CT_VATYPE));
|
||||
RETURN_SEMA_ERROR(type_info, "'%s' can only be used inside of a macro with untyped vaargs.", token_type_to_string(TOKEN_CT_VATYPE));
|
||||
}
|
||||
ASSIGN_EXPR_OR_RET(Expr *arg_expr, sema_expr_analyse_ct_arg_index(context, type_info->unresolved_type_expr, NULL), false);
|
||||
if (!sema_analyse_expr(context, arg_expr)) return false;
|
||||
|
||||
14
test/test_suite/macros/macro_vaarg_no.c3
Normal file
14
test/test_suite/macros/macro_vaarg_no.c3
Normal file
@@ -0,0 +1,14 @@
|
||||
import std;
|
||||
|
||||
macro void example(String... x)
|
||||
{
|
||||
$for var $i = 0; $i < $vacount; $i++: // #error: can only be used inside of a macro with untyped
|
||||
io::printn($vaarg[$i]);
|
||||
$endfor
|
||||
}
|
||||
|
||||
fn void main()
|
||||
{
|
||||
example();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user