Fix macro calls to make CT parameters modifiable.

This commit is contained in:
Christoffer Lerno
2022-08-11 11:04:44 +02:00
parent 90dfc24491
commit af9b99bd5a
4 changed files with 33 additions and 3 deletions

View File

@@ -57,10 +57,9 @@ macro void clear(void* dst, usize len, usize $dst_align = 0, bool $is_volatile =
* @require $typeof(a).kind != TypeKind.POINTER || len > -1
* @checked (a = b), (b = a)
**/
macro bool equals(a, b, isize len = -1, usize $alignment = 0)
macro bool equals(a, b, isize len = -1, usize $align = 0)
{
var $align = $alignment;
$if (!$alignment):
$if (!$align):
$align = $alignof($typeof(a[0]));
$endif;
void* x = void;

View File

@@ -1866,6 +1866,11 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s
{
Decl *param = params[i];
param->var.init_expr = args[i];
VarDeclKind kind = param->var.kind;
if (kind == VARDECL_PARAM_CT_TYPE || kind == VARDECL_PARAM_CT)
{
param->var.scope_depth = context->active_scope.depth + 1;
}
}
Decl **body_params = call_expr->call_expr.body_arguments;

View File

@@ -0,0 +1,13 @@
module test;
macro test($baz, $Type)
{
$baz = 123;
$Type = int;
}
fn void main()
{
var $foo = 1;
$foo = 4;
test(4, double);
}

View File

@@ -0,0 +1,13 @@
module test;
macro test($baz, $Type)
{
$baz = 123;
$Type = int;
}
fn void main()
{
var $foo = 1;
$foo = 4;
test(4, double);
}