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 @@ -285,7 +285,9 @@ impl Check<'_> {
285
285
bail ! ( "The local id used in PlaceExpression::Field is invalid." )
286
286
} ;
287
287
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
+ } ;
289
291
290
292
let (
291
293
_,
@@ -373,7 +375,9 @@ impl Check<'_> {
373
375
Ok ( constant. get_ty ( ) )
374
376
}
375
377
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
+ } ;
377
381
378
382
// Check the validity of the struct.
379
383
let (
Original file line number Diff line number Diff line change @@ -830,7 +830,7 @@ fn test_field_projection_root_non_adt() {
830
830
}
831
831
]
832
832
[ ]
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. " ]
834
834
)
835
835
}
836
836
@@ -864,3 +864,31 @@ fn test_struct_wrong_type_in_initialisation() {
864
864
expect_test:: expect![ "The type in ValueExpression::Tuple does not match the struct declared" ]
865
865
)
866
866
}
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
+ }
You can’t perform that action at this time.
0 commit comments