compiler: Fix function constness marking

This commit is contained in:
Alex Badics 2025-02-20 19:21:19 +01:00 committed by Olivier Goffart
parent 848e54a9ac
commit d173fa0ba9

View file

@ -1047,7 +1047,9 @@ impl Expression {
Expression::StructFieldAccess { base, .. } => base.is_constant(),
Expression::ArrayIndex { array, index } => array.is_constant() && index.is_constant(),
Expression::Cast { from, .. } => from.is_constant(),
Expression::CodeBlock(sub) => sub.len() == 1 && sub.first().unwrap().is_constant(),
// This is conservative: the return value is the last expression in the block, but
// we kind of mean "pure" here too, so ensure the whole body is OK.
Expression::CodeBlock(sub) => sub.iter().all(|s| s.is_constant()),
Expression::FunctionCall { function, arguments, .. } => {
let is_const = match function {
Callable::Builtin(b) => b.is_const(),