parser: fix if expression
							parent
							
								
									0382331499
								
							
						
					
					
						commit
						3d235169c8
					
				| 
						 | 
					@ -2499,7 +2499,7 @@ fn (p mut Parser) if_st(is_expr bool, elif_depth int) string {
 | 
				
			||||||
			//println('IF EXPR')
 | 
								//println('IF EXPR')
 | 
				
			||||||
		//}
 | 
							//}
 | 
				
			||||||
		p.inside_if_expr = true
 | 
							p.inside_if_expr = true
 | 
				
			||||||
		p.gen('(')
 | 
							p.gen('((')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else {
 | 
						else {
 | 
				
			||||||
		p.gen('if (')
 | 
							p.gen('if (')
 | 
				
			||||||
| 
						 | 
					@ -2594,7 +2594,7 @@ fn (p mut Parser) if_st(is_expr bool, elif_depth int) string {
 | 
				
			||||||
		p.inside_if_expr = false
 | 
							p.inside_if_expr = false
 | 
				
			||||||
		if is_expr {
 | 
							if is_expr {
 | 
				
			||||||
			p.check_types(first_typ, typ)
 | 
								p.check_types(first_typ, typ)
 | 
				
			||||||
			p.gen(strings.repeat(`)`, elif_depth + 1))
 | 
								p.gen(strings.repeat(`)`, 2 * (elif_depth + 1)))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else_returns := p.returns
 | 
							else_returns := p.returns
 | 
				
			||||||
		p.returns = if_returns && else_returns
 | 
							p.returns = if_returns && else_returns
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,14 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn test_if_expression_precedence_false_condition(){
 | 
				
			||||||
 | 
						b := 10
 | 
				
			||||||
 | 
						c := 20
 | 
				
			||||||
 | 
						res := 1 + if b > c { b } else { c } + 1
 | 
				
			||||||
 | 
						assert res == c + 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn test_if_expression_precedence_true_condition(){
 | 
				
			||||||
 | 
						b := 20
 | 
				
			||||||
 | 
						c := 10
 | 
				
			||||||
 | 
						res := 1 + if b > c { b } else { c } + 1
 | 
				
			||||||
 | 
						assert res == b + 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue