@@ -1068,3 +1068,57 @@ fn test_freeze_ref_no_arg() {
1068
1068
let fun_context = get_fun_context ( & module) ;
1069
1069
let _result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
1070
1070
}
1071
+
1072
+
1073
+ #[ test]
1074
+ fn test_read_ref_correct_type ( ) {
1075
+ for instr in vec ! [
1076
+ Bytecode :: ImmBorrowLoc ( 0 ) ,
1077
+ Bytecode :: MutBorrowLoc ( 0 ) ,
1078
+ ] {
1079
+ let code = vec ! [ instr, Bytecode :: ReadRef ] ;
1080
+ let module = make_module_with_local ( code, SignatureToken :: U64 ) ;
1081
+ let fun_context = get_fun_context ( & module) ;
1082
+ let result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
1083
+ assert ! ( result. is_ok( ) ) ;
1084
+ }
1085
+ }
1086
+
1087
+ #[ test]
1088
+ fn test_read_ref_wrong_type ( ) {
1089
+ let code = vec ! [ Bytecode :: LdU64 ( 42 ) , Bytecode :: ReadRef ] ;
1090
+ let module = make_module_with_local ( code, SignatureToken :: U64 ) ;
1091
+ let fun_context = get_fun_context ( & module) ;
1092
+ let result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
1093
+ assert_eq ! (
1094
+ result. unwrap_err( ) . major_status( ) ,
1095
+ StatusCode :: READREF_TYPE_MISMATCH_ERROR
1096
+ ) ;
1097
+ }
1098
+
1099
+ #[ test]
1100
+ fn test_read_ref_no_copy ( ) {
1101
+ for instr in vec ! [
1102
+ Bytecode :: ImmBorrowLoc ( 0 ) ,
1103
+ Bytecode :: MutBorrowLoc ( 0 ) ,
1104
+ ] {
1105
+ let code = vec ! [ instr, Bytecode :: ReadRef ] ;
1106
+ let mut module = make_module_with_local ( code, SignatureToken :: Struct ( StructHandleIndex ( 0 ) ) ) ;
1107
+ add_simple_struct_with_abilities ( & mut module, AbilitySet :: EMPTY ) ;
1108
+ let fun_context = get_fun_context ( & module) ;
1109
+ let result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
1110
+ assert_eq ! (
1111
+ result. unwrap_err( ) . major_status( ) ,
1112
+ StatusCode :: READREF_WITHOUT_COPY_ABILITY
1113
+ ) ;
1114
+ }
1115
+ }
1116
+
1117
+ #[ test]
1118
+ #[ should_panic]
1119
+ fn test_read_ref_no_arg ( ) {
1120
+ let code = vec ! [ Bytecode :: ReadRef ] ;
1121
+ let module = make_module_with_local ( code, SignatureToken :: U64 ) ;
1122
+ let fun_context = get_fun_context ( & module) ;
1123
+ let _result = type_safety:: verify ( & module, & fun_context, & mut DummyMeter ) ;
1124
+ }
0 commit comments