File tree 2 files changed +33
-3
lines changed
2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -212,4 +212,28 @@ mod tests {
212
212
let op = op_builder ( lhs, invalid_rhs, Overflow :: Wrapping ) ;
213
213
let _op = op. unwrap ( ) ;
214
214
}
215
+
216
+ /// Fails if [`InvalidOpsWithReturn`] is created successfully. [`InvalidOpsWithReturn`] is a
217
+ /// struct that has differing types in its result and arguments, despite implementing the
218
+ /// [`SameOperandsAndResultType`] trait.
219
+ #[ test]
220
+ #[ should_panic = "expected 'u32', got 'i32'" ]
221
+ fn same_operands_and_result_type_verifier_test ( ) {
222
+ use crate :: { SourceSpan , Type } ;
223
+
224
+ let context = Rc :: new ( Context :: default ( ) ) ;
225
+ let block = context. create_block_with_params ( [ Type :: I32 , Type :: I32 ] ) ;
226
+ let ( lhs, rhs) = {
227
+ let block = block. borrow ( ) ;
228
+ let lhs = block. get_argument ( 0 ) . upcast :: < dyn crate :: Value > ( ) ;
229
+ let rhs = block. get_argument ( 1 ) . upcast :: < dyn crate :: Value > ( ) ;
230
+ ( lhs, rhs)
231
+ } ;
232
+ let mut builder = context. builder ( ) ;
233
+ builder. set_insertion_point_to_end ( block) ;
234
+ // Try to create instance of AddOp with mismatched operand types
235
+ let op_builder = builder. create :: < InvalidOpsWithReturn , _ > ( SourceSpan :: default ( ) ) ;
236
+ let op = op_builder ( lhs, rhs) ;
237
+ let _op = op. unwrap ( ) ;
238
+ }
215
239
}
Original file line number Diff line number Diff line change @@ -75,10 +75,11 @@ impl InferTypeOpInterface for Shl {
75
75
}
76
76
}
77
77
78
- /// Invalid operation that breaks the SameOperandsAndResultType trait
78
+ /// Invalid operation that breaks the SameOperandsAndResultType trait (used for testing).
79
79
#[ operation(
80
80
dialect = TestDialect ,
81
81
traits( BinaryOp , SameTypeOperands , SameOperandsAndResultType ) ,
82
+ implements( InferTypeOpInterface )
82
83
) ]
83
84
pub struct InvalidOpsWithReturn {
84
85
#[ operand]
@@ -87,6 +88,11 @@ pub struct InvalidOpsWithReturn {
87
88
rhs : AnyInteger ,
88
89
#[ result]
89
90
result : AnyUnsignedInteger ,
90
- #[ attr]
91
- overflow : Overflow ,
91
+ }
92
+
93
+ impl InferTypeOpInterface for InvalidOpsWithReturn {
94
+ fn infer_return_types ( & mut self , context : & Context ) -> Result < ( ) , Report > {
95
+ self . result_mut ( ) . set_type ( Type :: U64 ) ;
96
+ Ok ( ( ) )
97
+ }
92
98
}
You can’t perform that action at this time.
0 commit comments