Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions crates/cairo-lang-semantic/src/expr/test_data/constant
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,26 @@ impl AnotherFoo<impl F: Foo> of Foo {
}

//! > expected_diagnostics

//! > ==========================================================================

//! > User-defined extern const fn in constant expression.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {}

//! > function_name
foo

//! > module_code
extern const fn f() -> felt252 nopanic;
const X: felt252 = f();

//! > expected_diagnostics
error[E2127]: This expression is not supported as constant.
--> lib.cairo:2:20
const X: felt252 = f();
^^^
11 changes: 7 additions & 4 deletions crates/cairo-lang-semantic/src/items/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cairo_lang_debug::DebugWithDb;
use cairo_lang_defs::db::DefsGroup;
use cairo_lang_defs::ids::{
ConstantId, ExternFunctionId, GenericParamId, LanguageElementId, LookupItemId, ModuleItemId,
NamedLanguageElementId, TopLevelLanguageElementId, TraitConstantId, TraitId, VarId,
NamedLanguageElementId, TraitConstantId, TraitId, VarId,
};
use cairo_lang_diagnostics::{
DiagnosticAdded, DiagnosticEntry, DiagnosticNote, Diagnostics, Maybe, MaybeAsRef,
Expand Down Expand Up @@ -1085,9 +1085,12 @@ impl<'a, 'r, 'mt> ConstantEvaluateContext<'a, 'r, 'mt> {
.intern(db),
);
} else {
unreachable!(
"Unexpected extern function in constant lowering: `{}`",
extern_fn.full_path(db)
return Some(
ConstValue::Missing(self.diagnostics.report(
expr.stable_ptr.untyped(),
SemanticDiagnosticKind::UnsupportedConstant,
))
.intern(db),
);
}
}
Expand Down
Loading