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