gen: fix generic comp time if (#8254)
							parent
							
								
									d8c94cd1fd
								
							
						
					
					
						commit
						0d204603d1
					
				|  | @ -213,6 +213,11 @@ fn (mut g Gen) comp_if(node ast.IfExpr) { | |||
| 			if should_create_scope { | ||||
| 				g.writeln('}') | ||||
| 			} | ||||
| 			if !comp_if_stmts_skip && branch.cond is ast.InfixExpr { | ||||
| 				if (branch.cond as ast.InfixExpr).op == .key_is { | ||||
| 					break | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		g.defer_ifdef = '' | ||||
| 	} | ||||
|  |  | |||
|  | @ -80,3 +80,24 @@ fn test_generic_t_is3() { | |||
| 	} | ||||
| 	assert res == GenericTIsTest{} | ||||
| } | ||||
| 
 | ||||
| fn test_generic_t_is_with_else() { | ||||
| 	res := generic_t_is_with_else<GenericTIsTest>('') or { | ||||
| 		assert false | ||||
| 		GenericTIsTest{} | ||||
| 	} | ||||
| 	assert res == GenericTIsTest{} | ||||
| 	str := generic_t_is_with_else<string>('test') or { | ||||
| 		assert false | ||||
| 		'' | ||||
| 	} | ||||
| 	assert str == 'test' | ||||
| } | ||||
| 
 | ||||
| fn generic_t_is_with_else<T>(raw_data string) ?T { | ||||
| 	$if T is string { | ||||
| 		return raw_data | ||||
| 	} $else { | ||||
| 		return T{} | ||||
| 	} | ||||
| } | ||||
		Loading…
	
		Reference in New Issue