diff --git a/crates/cairo-lang-semantic/src/expr/compute.rs b/crates/cairo-lang-semantic/src/expr/compute.rs index 255cfaf6626..2dd5623cfff 100644 --- a/crates/cairo-lang-semantic/src/expr/compute.rs +++ b/crates/cairo-lang-semantic/src/expr/compute.rs @@ -62,7 +62,7 @@ use crate::diagnostic::{ ElementKind, MultiArmExprKind, NotFoundItemType, SemanticDiagnostics, SemanticDiagnosticsBuilder, TraitInferenceErrors, UnsupportedOutsideOfFunctionFeatureName, }; -use crate::items::constant::{ConstValue, resolve_const_expr_and_evaluate}; +use crate::items::constant::{ConstValue, resolve_const_expr_and_evaluate, validate_const_expr}; use crate::items::enm::SemanticEnumEx; use crate::items::feature_kind::extract_item_feature_config; use crate::items::functions::function_signature_params; @@ -1085,7 +1085,9 @@ pub fn compute_root_expr( inference.finalize(ctx.diagnostics, syntax.into()); ctx.apply_inference_rewriter(); - + if ctx.signature.map(|s| s.is_const) == Some(true) { + validate_const_expr(ctx, res); + } Ok(res) } diff --git a/crates/cairo-lang-semantic/src/items/constant.rs b/crates/cairo-lang-semantic/src/items/constant.rs index 3f136fe5b1c..e98b6f48ba1 100644 --- a/crates/cairo-lang-semantic/src/items/constant.rs +++ b/crates/cairo-lang-semantic/src/items/constant.rs @@ -361,6 +361,13 @@ pub fn constant_semantic_data_cycle_helper( }) } +/// Checks if the given expression only involved constant calculations. +pub fn validate_const_expr(ctx: &mut ComputationContext<'_>, expr_id: ExprId) { + let mut eval_ctx = + ConstantEvaluateContext { db: ctx.db, arenas: &ctx.arenas, diagnostics: ctx.diagnostics }; + eval_ctx.validate(expr_id); +} + /// Resolves the given const expression and evaluates its value. pub fn resolve_const_expr_and_evaluate( db: &dyn SemanticGroup,