@@ -827,20 +827,42 @@ fn monomorphize_expr<B: Backend>(
827
827
let ExprMonoInfo { expr : rhs_expr, .. } = rhs_mono;
828
828
829
829
// fold constants
830
- let cst = match ( & lhs_expr. kind , & rhs_expr. kind ) {
831
- ( ExprKind :: BigUInt ( lhs) , ExprKind :: BigUInt ( rhs) ) => match op {
832
- Op2 :: Addition => Some ( lhs + rhs) ,
833
- Op2 :: Subtraction => Some ( lhs - rhs) ,
834
- Op2 :: Multiplication => Some ( lhs * rhs) ,
835
- Op2 :: Division => Some ( lhs / rhs) ,
836
- _ => None ,
837
- } ,
830
+ let cst = match ( & lhs_mono. constant , & rhs_mono. constant ) {
831
+ ( Some ( PropagatedConstant :: Single ( lhs) ) , Some ( PropagatedConstant :: Single ( rhs) ) ) => {
832
+ match op {
833
+ Op2 :: Addition => Some ( lhs + rhs) ,
834
+ Op2 :: Subtraction => {
835
+ if lhs < rhs {
836
+ // throw error
837
+ return Err ( error (
838
+ ErrorKind :: NegativeLhsLessThanRhs (
839
+ lhs. to_string ( ) ,
840
+ rhs. to_string ( ) ,
841
+ ) ,
842
+ expr. span ,
843
+ ) ) ;
844
+ }
845
+ Some ( lhs - rhs)
846
+ }
847
+ Op2 :: Multiplication => Some ( lhs * rhs) ,
848
+ Op2 :: Division => Some ( lhs / rhs) ,
849
+ _ => None ,
850
+ }
851
+ }
838
852
_ => None ,
839
853
} ;
840
854
841
855
match cst {
842
856
Some ( v) => {
843
- let mexpr = expr. to_mast ( ctx, & ExprKind :: BigUInt ( v. clone ( ) ) ) ;
857
+ let mexpr = expr. to_mast (
858
+ ctx,
859
+ & ExprKind :: BinaryOp {
860
+ op : op. clone ( ) ,
861
+ protected : * protected,
862
+ lhs : Box :: new ( lhs_expr) ,
863
+ rhs : Box :: new ( rhs_expr) ,
864
+ } ,
865
+ ) ;
844
866
845
867
ExprMonoInfo :: new ( mexpr, typ, Some ( PropagatedConstant :: from ( v) ) )
846
868
}
0 commit comments