Skip to content

Commit d76e56c

Browse files
committed
Add more checks and test
1 parent 321877d commit d76e56c

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
@@ -285,7 +285,9 @@ impl Check<'_> {
285285
bail!("The local id used in PlaceExpression::Field is invalid.")
286286
};
287287

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

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

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

src/test/mir_fn_bodies.rs

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

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

0 commit comments

Comments
 (0)