Copy cexprs to keep AST nodes unique/unshared
This commit is contained in:
parent
7569420fe0
commit
fb75434cba
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user