diff --git a/v2/engine/function.c b/v2/engine/function.c index 78d5f223c..b871f2c37 100644 --- a/v2/engine/function.c +++ b/v2/engine/function.c @@ -2167,19 +2167,18 @@ static void compile_parse( PARSE * parse, compiler * c, int result_location ) } else if( parse->type == PARSE_IF ) { - int nested_result = result_location == RESULT_NONE? RESULT_NONE : RESULT_RETURN; int f = compile_new_label( c ); /* Emit the condition */ compile_condition( parse->left, c, 0, f ); /* Emit the if block */ - compile_parse( parse->right, c, nested_result ); - if ( parse->third->type != PARSE_NULL ) + compile_parse( parse->right, c, result_location ); + if ( parse->third->type != PARSE_NULL || result_location != RESULT_NONE ) { /* Emit the else block */ int end = compile_new_label( c ); compile_emit_branch( c, INSTR_JUMP, end ); compile_set_label( c, f ); - compile_parse( parse->third, c, nested_result ); + compile_parse( parse->third, c, result_location ); compile_set_label( c, end ); } else @@ -2187,7 +2186,6 @@ static void compile_parse( PARSE * parse, compiler * c, int result_location ) compile_set_label( c, f ); } - adjust_result( c, nested_result, result_location); } else if( parse->type == PARSE_WHILE ) { diff --git a/v2/test/core-language/test.jam b/v2/test/core-language/test.jam index d0f493f8e..6b8b307bb 100644 --- a/v2/test/core-language/test.jam +++ b/v2/test/core-language/test.jam @@ -359,6 +359,61 @@ else check-order if-else-false : r2 ; +rule test-rule +{ + if true + { + return result ; + } +} + +check-equal if-true-result : [ test-rule ] : result ; + +rule test-rule +{ + local idx = 1 2 ; + local values = true ; + while $(idx) + { + local v = $(values[$(idx[1])]) ; + idx = $(idx[2-]) ; + if $(v) + { + return result ; + } + } +} + +check-equal if-false-result : [ test-rule ] : ; + +rule test-rule +{ + if true + { + return r1 ; + } + else + { + return r2 ; + } +} + +check-equal if-else-true-result : [ test-rule ] : r1 ; + +rule test-rule +{ + if $(false) + { + return r1 ; + } + else + { + return r2 ; + } +} + +check-equal if-else-false-result : [ test-rule ] : r2 ; + } # Check the evaluation of conditions