File tree 3 files changed +34
-4
lines changed
3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -211,4 +211,28 @@ mod tests {
211
211
let op = op_builder ( lhs, invalid_rhs, Overflow :: Wrapping ) ;
212
212
let _op = op. unwrap ( ) ;
213
213
}
214
+
215
+ /// Fails if [`InvalidOpsWithReturn`] is created successfully. [`InvalidOpsWithReturn`] is a
216
+ /// struct that has differing types in its result and arguments, despite implementing the
217
+ /// [`SameOperandsAndResultType`] trait.
218
+ #[ test]
219
+ #[ should_panic = "expected 'i32', got 'u64'" ]
220
+ fn same_operands_and_result_type_verifier_test ( ) {
221
+ use crate :: { SourceSpan , Type } ;
222
+
223
+ let context = Rc :: new ( Context :: default ( ) ) ;
224
+ let block = context. create_block_with_params ( [ Type :: I32 , Type :: I32 ] ) ;
225
+ let ( lhs, rhs) = {
226
+ let block = block. borrow ( ) ;
227
+ let lhs = block. get_argument ( 0 ) . upcast :: < dyn crate :: Value > ( ) ;
228
+ let rhs = block. get_argument ( 1 ) . upcast :: < dyn crate :: Value > ( ) ;
229
+ ( lhs, rhs)
230
+ } ;
231
+ let mut builder = context. builder ( ) ;
232
+ builder. set_insertion_point_to_end ( block) ;
233
+ // Try to create instance of AddOp with mismatched operand types
234
+ let op_builder = builder. create :: < InvalidOpsWithReturn , _ > ( SourceSpan :: default ( ) ) ;
235
+ let op = op_builder ( lhs, rhs) ;
236
+ let _op = op. unwrap ( ) ;
237
+ }
214
238
}
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
}
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ derive! {
86
86
( value. ty( ) . clone( ) , value. span( ) )
87
87
} ;
88
88
89
- let mut results = op. results( ) . iter( ) ;
89
+ let results = op. results( ) . iter( ) ;
90
90
91
91
for operand in operands {
92
92
let operand = operand. borrow( ) ;
You can’t perform that action at this time.
0 commit comments