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
32 changes: 32 additions & 0 deletions crates/cairo-lang-semantic/src/expr/test_data/constant
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,35 @@ error[E2127]: This expression is not supported as constant.
--> lib.cairo:2:20
const X: felt252 = f();
^^^

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

//! > Statement-level const struct literal with missing field.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {
const X: S = S { a: 1 };
}

//! > function_name
foo

//! > module_code
struct S {
a: felt252,
b: felt252,
}

//! > expected_diagnostics
error[E0003]: Missing member "b".
--> lib.cairo:6:18
const X: S = S { a: 1 };
^^^^^^^^^^

warning[E2070]: Unused constant. Consider ignoring by prefixing with `_`.
--> lib.cairo:6:11
const X: S = S { a: 1 };
^
3 changes: 2 additions & 1 deletion crates/cairo-lang-semantic/src/items/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,8 @@ impl<'a, 'r, 'mt> ConstantEvaluateContext<'a, 'r, 'mt> {
.iter()
.find(|(_, member_id)| m.id == *member_id)
.map(|(expr_id, _)| self.evaluate(*expr_id))
.expect("Should have been caught by semantic validation")
// A missing field should have been caught by semantic validation.
.unwrap_or_else(|| ConstValue::Missing(skip_diagnostic()).intern(db))
})
.collect(),
*ty,
Expand Down
Loading