File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed
crates/formality-check/src Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -284,7 +284,9 @@ impl Check<'_> {
284
284
bail ! ( "The local id used in PlaceExpression::Field is invalid." )
285
285
} ;
286
286
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
+ } ;
288
290
289
291
let (
290
292
_,
@@ -372,7 +374,9 @@ impl Check<'_> {
372
374
Ok ( constant. get_ty ( ) )
373
375
}
374
376
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
+ } ;
376
380
377
381
// Check the validity of the struct.
378
382
let (
Original file line number Diff line number Diff line change @@ -834,7 +834,7 @@ fn test_field_projection_root_non_adt() {
834
834
}
835
835
]
836
836
[ ]
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. " ]
838
838
)
839
839
}
840
840
@@ -868,3 +868,31 @@ fn test_struct_wrong_type_in_initialisation() {
868
868
expect_test:: expect![ "The type in ValueExpression::Tuple does not match the struct declared" ]
869
869
)
870
870
}
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
+ }
You can’t perform that action at this time.
0 commit comments