From fb75434cba21222d92d8f6546d9073d3ea7fc270 Mon Sep 17 00:00:00 2001 From: Mid <> Date: Thu, 2 Oct 2025 13:38:27 +0300 Subject: [PATCH] Copy cexprs to keep AST nodes unique/unshared --- src/ast/ast.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ast/ast.c b/src/ast/ast.c index cae4c87..cbe1bd1 100644 --- a/src/ast/ast.c +++ b/src/ast/ast.c @@ -242,12 +242,19 @@ AST *ast_cast_expr(AST *what, Type *to) { } else abort(); } + bool copy = false; + // Make sure an unparametrized generic int parameter hasn't sneaked its way in while(what->nodeKind == AST_EXPR_VAR && what->exprVar.thing->kind == SCOPEITEM_CEXPR && what->exprVar.thing->data.cexpr.concrete) { what = what->exprVar.thing->data.cexpr.concrete; + copy = true; } assert(!(what->nodeKind == AST_EXPR_VAR && what->exprVar.thing->kind == SCOPEITEM_CEXPR)); + if(copy) { + what = ast_deep_copy(what); + } + if(type_equal(what->expression.type, to)) return what; if(!type_is_castable(what->expression.type, to)) {