diff --git a/crates/cairo-lang-semantic/src/expr/test_data/constant b/crates/cairo-lang-semantic/src/expr/test_data/constant index 3ea833085ba..b3e902062ce 100644 --- a/crates/cairo-lang-semantic/src/expr/test_data/constant +++ b/crates/cairo-lang-semantic/src/expr/test_data/constant @@ -709,6 +709,36 @@ impl AnotherFoo of Foo { //! > ========================================================================== +//! > Const not with generic impl constants is unsupported. + +//! > test_runner_name +test_function_diagnostics(expect_diagnostics: true) + +//! > function_code +fn foo() {} + +//! > function_name +foo + +//! > module_code +trait FlagTrait { + const FLAG: bool; +} +impl AFlag of FlagTrait { + const FLAG: bool = true; +} +impl AnotherFlag of FlagTrait { + const FLAG: bool = !F::FLAG; +} + +//! > expected_diagnostics +error[E2127]: This expression is not supported as constant. + --> lib.cairo:8:24 + const FLAG: bool = !F::FLAG; + ^^^^^^^^ + +//! > ========================================================================== + //! > User-defined extern const fn in constant expression. //! > test_runner_name diff --git a/crates/cairo-lang-semantic/src/items/constant.rs b/crates/cairo-lang-semantic/src/items/constant.rs index 288a8694f5d..34ef0879f87 100644 --- a/crates/cairo-lang-semantic/src/items/constant.rs +++ b/crates/cairo-lang-semantic/src/items/constant.rs @@ -893,6 +893,18 @@ impl<'a, 'r, 'mt> ConstantEvaluateContext<'a, 'r, 'mt> { if condition { self.true_const } else { self.false_const } }; + let has_non_concrete_arg = args.iter().any(|arg| { + !arg.is_fully_concrete(db) && !matches!(arg.long(db), ConstValue::Missing(_)) + }); + if (imp.function == self.eq_fn || imp.function == self.ne_fn || imp.function == self.not_fn) + && has_non_concrete_arg + { + return to_missing( + self.diagnostics + .report(expr.stable_ptr.untyped(), SemanticDiagnosticKind::UnsupportedConstant), + ); + } + if imp.function == self.eq_fn { return bool_value(args[0] == args[1]); } else if imp.function == self.ne_fn {