Copy cexprs to keep AST nodes unique/unshared

This commit is contained in:
Mid 2025-10-02 13:38:27 +03:00
parent 7569420fe0
commit fb75434cba

View File

@ -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)) {