Skip to content

Commit d06c9ac

Browse files
committed
Add more checks and test
1 parent a259587 commit d06c9ac

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

crates/formality-check/src/mini_rust_check.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ impl Check<'_> {
284284
bail!("The local id used in PlaceExpression::Field is invalid.")
285285
};
286286

287-
let adt_id = ty.get_adt_id().unwrap();
287+
let Some(adt_id) = ty.get_adt_id() else {
288+
bail!("The local used for field projection is not adt.")
289+
};
288290

289291
let (
290292
_,
@@ -372,7 +374,9 @@ impl Check<'_> {
372374
Ok(constant.get_ty())
373375
}
374376
Struct(value_expressions, ty) => {
375-
let adt_id = ty.get_adt_id().unwrap();
377+
let Some(adt_id) = ty.get_adt_id() else {
378+
bail!("The type used in ValueExpression::Struct must be adt")
379+
};
376380

377381
// Check the validity of the struct.
378382
let (

src/test/mir_fn_bodies.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ fn test_field_projection_root_non_adt() {
834834
}
835835
]
836836
[]
837-
expect_test::expect!["The type for field projection must be adt"]
837+
expect_test::expect!["The local used for field projection is not adt."]
838838
)
839839
}
840840

@@ -868,3 +868,31 @@ fn test_struct_wrong_type_in_initialisation() {
868868
expect_test::expect!["The type in ValueExpression::Tuple does not match the struct declared"]
869869
)
870870
}
871+
872+
/// Test the behaviour of having non-adt as the type for ValueExpression::Struct.
873+
#[test]
874+
fn test_non_adt_ty_for_struct() {
875+
crate::assert_err!(
876+
[
877+
crate Foo {
878+
879+
fn foo (u32) -> u32 = minirust(v1) -> v0 {
880+
let v0: u32;
881+
let v1: u32;
882+
let v2: u32;
883+
884+
bb0: {
885+
statements {
886+
local(v0) = load(local(v1));
887+
local(v2) = struct { constant(false) } as u32;
888+
}
889+
return;
890+
}
891+
892+
};
893+
}
894+
]
895+
[]
896+
expect_test::expect!["The type used in ValueExpression::Struct must be adt"]
897+
)
898+
}

0 commit comments

Comments
 (0)