gen: c don't generate x >= 0 check for unsigned ints in range exprs in matches (#6414)
							parent
							
								
									f7aa9cb0c5
								
							
						
					
					
						commit
						ffc8cf3925
					
				|  | @ -2671,11 +2671,21 @@ fn (mut g Gen) match_expr(node ast.MatchExpr) { | ||||||
| 					g.expr(expr) | 					g.expr(expr) | ||||||
| 					g.write(')') | 					g.write(')') | ||||||
| 				} else if expr is ast.RangeExpr { | 				} else if expr is ast.RangeExpr { | ||||||
|  | 					// if type is unsigned and low is 0, check is unneeded
 | ||||||
|  | 					mut skip_low := false | ||||||
|  | 					if expr.low is ast.IntegerLiteral as expr_low { | ||||||
|  | 						if node.cond_type in [table.u16_type, table.u32_type, table.u64_type] && | ||||||
|  | 							expr_low.val == '0' { | ||||||
|  | 							skip_low = true | ||||||
|  | 						} | ||||||
|  | 					} | ||||||
| 					g.write('(') | 					g.write('(') | ||||||
| 					g.write(cond_var) | 					if !skip_low { | ||||||
| 					g.write(' >= ') | 						g.write(cond_var) | ||||||
| 					g.expr(expr.low) | 						g.write(' >= ') | ||||||
| 					g.write(' && ') | 						g.expr(expr.low) | ||||||
|  | 						g.write(' && ') | ||||||
|  | 					} | ||||||
| 					g.write(cond_var) | 					g.write(cond_var) | ||||||
| 					g.write(' <= ') | 					g.write(' <= ') | ||||||
| 					g.expr(expr.high) | 					g.expr(expr.high) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue