Author: jsuchome Date: Fri Jun 17 16:40:18 2011 New Revision: 64458 URL: http://svn.opensuse.org/viewcvs/yast?rev=64458&view=rev Log: - when if-condition evaluates to nil, use false instead (bnc#687236) - 2.21.4 Added: trunk/core/libycp/testsuite/tests/expressions/Triple2.err trunk/core/libycp/testsuite/tests/expressions/Triple2.out trunk/core/libycp/testsuite/tests/expressions/Triple2.ycp (with props) trunk/core/libycp/testsuite/tests/statements/If4.err trunk/core/libycp/testsuite/tests/statements/If4.out trunk/core/libycp/testsuite/tests/statements/If4.ycp (with props) Modified: trunk/core/VERSION trunk/core/libycp/src/YCPBuiltinBoolean.cc trunk/core/libycp/src/YExpression.cc trunk/core/libycp/src/YStatement.cc trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.err trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.out trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.ycp trunk/core/package/yast2-core.changes Modified: trunk/core/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/VERSION?rev=64458&r1=64457&r2=64458&view=diff ============================================================================== --- trunk/core/VERSION (original) +++ trunk/core/VERSION Fri Jun 17 16:40:18 2011 @@ -1 +1 @@ -2.21.3 +2.21.4 Modified: trunk/core/libycp/src/YCPBuiltinBoolean.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/YCPBuiltinBoolean.cc?rev=64458&r1=64457&r2=64458&view=diff ============================================================================== --- trunk/core/libycp/src/YCPBuiltinBoolean.cc (original) +++ trunk/core/libycp/src/YCPBuiltinBoolean.cc Fri Jun 17 16:40:18 2011 @@ -21,6 +21,10 @@ #include "ycp/YCPBoolean.h" #include "ycp/YCPCode.h" #include "ycp/StaticDeclaration.h" +#include "ycp/y2log.h" +#include "ycp/ExecutionEnvironment.h" + +extern ExecutionEnvironment ee; extern StaticDeclaration static_declarations; @@ -60,16 +64,18 @@ if (b1_v.isNull () || b1_v->isVoid ()) { - return YCPNull (); + ycp2warning (ee.filename().c_str(), ee.linenumber(), "First operand of '||' evaluates to nil, using 'false' instead."); } - - if (b1_v->asBoolean ()->value ()) + else if (b1_v->asBoolean ()->value ()) + { return YCPBoolean (true); + } YCPValue b2_v = b2->code ()->evaluate (); if (b2_v.isNull () || b2_v->isVoid ()) { - return YCPNull (); + ycp2warning (ee.filename().c_str(), ee.linenumber(), "Second operand of '||' evaluates to nil, using 'false' instead."); + return YCPBoolean (false); } return YCPBoolean (b2_v->asBoolean ()->value ()); @@ -92,7 +98,8 @@ if (b1_v.isNull () || b1_v->isVoid ()) { - return YCPNull (); + ycp2warning (ee.filename().c_str(), ee.linenumber(), "First operand of '&&' evaluates to nil, using 'false' instead."); + return YCPBoolean (false); } if (! b1_v->asBoolean ()->value ()) @@ -101,7 +108,8 @@ YCPValue b2_v = b2->code ()->evaluate (); if (b2_v.isNull () || b2_v->isVoid ()) { - return YCPNull (); + ycp2warning (ee.filename().c_str(), ee.linenumber(), "Second operand of '&&' evaluates to nil, using 'false' instead."); + return YCPBoolean (false); } return YCPBoolean (b2_v->asBoolean ()->value ()); Modified: trunk/core/libycp/src/YExpression.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/YExpression.cc?rev=64458&r1=64457&r2=64458&view=diff ============================================================================== --- trunk/core/libycp/src/YExpression.cc (original) +++ trunk/core/libycp/src/YExpression.cc Fri Jun 17 16:40:18 2011 @@ -1500,10 +1500,11 @@ YCPValue expr = m_expr->evaluate (); - if (expr.isNull ()) + if (expr.isNull () || expr->isVoid()) { - ycp2error ("Condition expression evaluates to nil in ?: expression"); - return YCPNull (); + extern ExecutionEnvironment ee; + ycp2warning (ee.filename().c_str(), ee.linenumber(), "Condition expression evaluates to nil in ?: expression, using false instead."); + return m_false->evaluate (); } if (expr->isBoolean()) Modified: trunk/core/libycp/src/YStatement.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/src/YStatement.cc?rev=64458&r1=64457&r2=64458&view=diff ============================================================================== --- trunk/core/libycp/src/YStatement.cc (original) +++ trunk/core/libycp/src/YStatement.cc Fri Jun 17 16:40:18 2011 @@ -1047,9 +1047,10 @@ if (!bval->isBoolean()) { - ycp2error ("'if (%s)' evaluates to non-boolean '%s' (%s).", m_condition->toString().c_str(), bval->toString().c_str(), bval->valuetype_str()); + ycp2warning (ee.filename().c_str(), ee.linenumber(), "'if (%s)' evaluates to non-boolean '%s' (%s), using 'false' instead.", m_condition->toString().c_str(), bval->toString().c_str(), bval->valuetype_str()); + bval = YCPBoolean (false); } - else if (bval->asBoolean()->value() == true) + if (bval->asBoolean()->value() == true) { if (m_true != 0) { Modified: trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.err URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.err?rev=64458&r1=64457&r2=64458&view=diff ============================================================================== --- trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.err (original) +++ trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.err Fri Jun 17 16:40:18 2011 @@ -82,3 +82,27 @@ ---------------------------------------------------------------------- (false || false) ---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(nil || true) +---------------------------------------------------------------------- +[Interpreter] tests/builtin/Builtin-Boolean.ycp:0 First operand of '||' evaluates to nil, using 'false' instead. +Parsed: +---------------------------------------------------------------------- +(true || nil) +---------------------------------------------------------------------- +Parsed: +---------------------------------------------------------------------- +(false || nil) +---------------------------------------------------------------------- +[Interpreter] tests/builtin/Builtin-Boolean.ycp:0 Second operand of '||' evaluates to nil, using 'false' instead. +Parsed: +---------------------------------------------------------------------- +(nil && true) +---------------------------------------------------------------------- +[Interpreter] tests/builtin/Builtin-Boolean.ycp:0 First operand of '&&' evaluates to nil, using 'false' instead. +Parsed: +---------------------------------------------------------------------- +(true && nil) +---------------------------------------------------------------------- +[Interpreter] tests/builtin/Builtin-Boolean.ycp:0 Second operand of '&&' evaluates to nil, using 'false' instead. Modified: trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.out URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.out?rev=64458&r1=64457&r2=64458&view=diff ============================================================================== --- trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.out (original) +++ trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.out Fri Jun 17 16:40:18 2011 @@ -19,3 +19,8 @@ (true) (true) (false) +(true) +(true) +(false) +(false) +(false) Modified: trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.ycp?rev=64458&r1=64457&r2=64458&view=diff ============================================================================== --- trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.ycp (original) +++ trunk/core/libycp/testsuite/tests/builtin/Builtin-Boolean.ycp Fri Jun 17 16:40:18 2011 @@ -39,3 +39,8 @@ (false || true) (false || false) +(nil || true) +(true || nil) +(false || nil) +(nil && true) +(true && nil) Added: trunk/core/libycp/testsuite/tests/expressions/Triple2.err URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/expressions/Triple2.err?rev=64458&view=auto ============================================================================== --- trunk/core/libycp/testsuite/tests/expressions/Triple2.err (added) +++ trunk/core/libycp/testsuite/tests/expressions/Triple2.err Fri Jun 17 16:40:18 2011 @@ -0,0 +1,10 @@ +Parsed: +---------------------------------------------------------------------- +{ + // boolean b + // filename: "tests/expressions/Triple2.ycp" + boolean b = nil; + return b ? 1 : 2; +} +---------------------------------------------------------------------- +[Interpreter] tests/expressions/Triple2.ycp:4 Condition expression evaluates to nil in ?: expression, using false instead. Added: trunk/core/libycp/testsuite/tests/expressions/Triple2.out URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/expressions/Triple2.out?rev=64458&view=auto ============================================================================== --- trunk/core/libycp/testsuite/tests/expressions/Triple2.out (added) +++ trunk/core/libycp/testsuite/tests/expressions/Triple2.out Fri Jun 17 16:40:18 2011 @@ -0,0 +1 @@ +(2) Added: trunk/core/libycp/testsuite/tests/expressions/Triple2.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/expressions/Triple2.ycp?rev=64458&view=auto ============================================================================== --- trunk/core/libycp/testsuite/tests/expressions/Triple2.ycp (added) +++ trunk/core/libycp/testsuite/tests/expressions/Triple2.ycp Fri Jun 17 16:40:18 2011 @@ -0,0 +1,5 @@ +{ + // nil variable evaluates as fals + boolean b = nil; + return (b ? 1 : 2); +} Added: trunk/core/libycp/testsuite/tests/statements/If4.err URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/statements/If4.err?rev=64458&view=auto ============================================================================== --- trunk/core/libycp/testsuite/tests/statements/If4.err (added) +++ trunk/core/libycp/testsuite/tests/statements/If4.err Fri Jun 17 16:40:18 2011 @@ -0,0 +1,43 @@ +Parsed: +---------------------------------------------------------------------- +{ + // boolean b + // filename: "tests/statements/If4.ycp" + boolean b = nil; + if (b) + { + return 1; +} +else + { + return 2; +} + return 3; +} +---------------------------------------------------------------------- +[Interpreter] tests/statements/If4.ycp:3 'if (b)' evaluates to non-boolean 'nil' (VOID), using 'false' instead. +Parsed: +---------------------------------------------------------------------- +{ + // boolean boolean_returing_function () + // filename: "tests/statements/If4.ycp" + boolean boolean_returing_function () +{ + // boolean ret + boolean ret = nil; + return ret; +} + if (boolean_returing_function ()) + { + return 1; +} +else + { + return 2; +} +} +---------------------------------------------------------------------- +[Interpreter] tests/statements/If4.ycp:18 'if (boolean_returing_function ())' evaluates to non-boolean 'nil' (RETURN), using 'false' instead. +[Parser] tests/statements/If4.ycp:29 'if' expression not boolean +[Parser] tests/statements/If4.ycp:29 Expected 'boolean', seen 'const void'. +runycp: parser error Added: trunk/core/libycp/testsuite/tests/statements/If4.out URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/statements/If4.out?rev=64458&view=auto ============================================================================== --- trunk/core/libycp/testsuite/tests/statements/If4.out (added) +++ trunk/core/libycp/testsuite/tests/statements/If4.out Fri Jun 17 16:40:18 2011 @@ -0,0 +1,2 @@ +(2) +(2) Added: trunk/core/libycp/testsuite/tests/statements/If4.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libycp/testsuite/tests/statements/If4.ycp?rev=64458&view=auto ============================================================================== --- trunk/core/libycp/testsuite/tests/statements/If4.ycp (added) +++ trunk/core/libycp/testsuite/tests/statements/If4.ycp Fri Jun 17 16:40:18 2011 @@ -0,0 +1,34 @@ +{ + boolean b = nil; + if (b) + { + return 1; + } + else + { + return 2; + } + return 3; // should not happen +} +{ + boolean boolean_returing_function () { + boolean ret = nil; + return ret; + } + if (boolean_returing_function ()) + { + return 1; + } + else + { + return 2; + } +} +{ + // this is real parse error + if (nil) + return 1; + return 2; +} + + Modified: trunk/core/package/yast2-core.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/package/yast2-core.changes?rev=64458&r1=64457&r2=64458&view=diff ============================================================================== --- trunk/core/package/yast2-core.changes (original) +++ trunk/core/package/yast2-core.changes Fri Jun 17 16:40:18 2011 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Fri Jun 17 16:21:50 CEST 2011 - jsuchome@suse.cz + +- when if-condition evaluates to nil, use false instead (bnc#687236) +- 2.21.4 + +------------------------------------------------------------------- Thu Jun 02 09:58:11 CEST 2011 - aschnell@suse.de - added missing include statements -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org