cgen: fix match expression with complex boolean conditions
							parent
							
								
									3cb1bb7c36
								
							
						
					
					
						commit
						c474106511
					
				|  | @ -3808,7 +3808,9 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str | |||
| 				} else { | ||||
| 					g.write(cond_var) | ||||
| 					g.write(' == ') | ||||
| 					g.write('(') | ||||
| 					g.expr(expr) | ||||
| 					g.write(')') | ||||
| 				} | ||||
| 			} | ||||
| 			if is_expr && tmp_var.len == 0 { | ||||
|  |  | |||
|  | @ -4,7 +4,9 @@ fn test_match_with_array_map_in_branches() { | |||
| 	arr := Arr([0, 1]) | ||||
| 	ret := match arr { | ||||
| 		[]int { | ||||
| 			arr.map(fn(s int) string { return s.str() }).str() | ||||
| 			arr.map(fn (s int) string { | ||||
| 				return s.str() | ||||
| 			}).str() | ||||
| 		} | ||||
| 		else { | ||||
| 			'' | ||||
|  | @ -29,3 +31,14 @@ fn test_match_expr_of_multi_expr_stmts() { | |||
| 	println(ret) | ||||
| 	assert ret == 2 | ||||
| } | ||||
| 
 | ||||
| fn test_match_expression_on_complex_bool_conditions() { | ||||
| 	s := 'hello' | ||||
| 	x := match true { | ||||
| 		s[1] == `e` { 'first' } | ||||
| 		(s[1] == `e`) { 'second' } | ||||
| 		else { 'not found' } | ||||
| 	} | ||||
| 	println(x) | ||||
| 	assert x == 'first' | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue