bugGNU Octave - Bugs: bug #63935, error during evaluation of...

 
 

bug #63935: error during evaluation of conditional in if

Submitter:  A.R. Burgers <arb>
Submitted:  Thu 16 Mar 2023 09:50:10 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  8.2.0 Planned Release:  8.2.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 11 Apr 2023 07:00:31 PM UTC, comment #13: 

Verified fix on stable branch.





This problem has been fixed in the stable version. The fix will
be available in the next minor software release. Thank you for
your bug report.

Rik <rik5>
Group administrator
Mon 20 Mar 2023 05:32:48 PM UTC, comment #12: 

Thanks for the test.  I pushed the following changes on stable.  Marking as ready for test.

http://hg.savannah.gnu.org/hgweb/octave/rev/c6827549b7d5
http://hg.savannah.gnu.org/hgweb/octave/rev/31f9e97759b4

John W. Eaton <jwe>
Group administrator
Sun 19 Mar 2023 08:16:12 AM UTC, comment #11: 

Think the test should look more like this


diff -r 685937390083 test/if.tst
--- a/test/if.tst       Sat Mar 18 15:37:12 2023 -0400
+++ b/test/if.tst       Sun Mar 19 09:14:12 2023 +0100
@@ -48,6 +48,16 @@
 %! endif
 %! assert (__prog_output_assert__ ("pass"));

+%!test <*63935>
+%! try
+%!   if true(4,1) & true(4,1)
+%!     __printf_assert__ ("pass\n");
+%!   endif
+%! catch
+%!   __printf_assert__ ("fail\n");
+%! end_try_catch
+%! assert (__prog_output_assert__ ("pass"));
+
 %!test
 %! x = 0;
 %! y = -2;


A.R. Burgers <arb>
Sat 18 Mar 2023 09:55:22 PM UTC, comment #10: 

maybe add a test as well:


diff -r 685937390083 test/if.tst
--- a/test/if.tst       Sat Mar 18 15:37:12 2023 -0400
+++ b/test/if.tst       Sat Mar 18 22:51:21 2023 +0100
@@ -48,6 +48,14 @@
 %! endif
 %! assert (__prog_output_assert__ ("pass"));

+%!test <63935>
+%! if true(4,1) & true(4,1)
+%!   __printf_assert__ ("pass\n");
+%! elseif (x)
+%!   __printf_assert__ ("fail\n");
+%! endif
+%! assert (__prog_output_assert__ ("pass"));
+
 %!test
 %! x = 0;
 %! y = -2;


A.R. Burgers <arb>
Fri 17 Mar 2023 11:17:44 PM UTC, comment #9: 

I introduced this error in https://hg.octave.org/octave/rev/7781b1e77406

The following change should fix it.


diff --git a/libinterp/parse-tree/pt-binop.cc b/libinterp/parse-tree/pt-binop.cc
--- a/libinterp/parse-tree/pt-binop.cc
+++ b/libinterp/parse-tree/pt-binop.cc
@@ -156,6 +156,8 @@ tree_braindead_shortcircuit_binary_expre

           return octave_value (result);
         }
+      else
+        return tree_binary_expression::evaluate (tw);
     }

   return octave_value ();


John W. Eaton <jwe>
Group administrator
Fri 17 Mar 2023 06:56:55 PM UTC, comment #8: 

I think that's not the correct evaluate function. It should be coming from the tree expression evaluator, not the tree evaluator.

CC jwe for help with parser logic.

Arun Giridhar <arungiridhar>
Group Member
Fri 17 Mar 2023 06:24:51 PM UTC, comment #7: 

Is this the correct evaluate function that is being called?


   1834 octave_value
   1835 tree_evaluator::evaluate (tree_decl_elt *elt)
   1836 {
   1837   // Do not allow functions to return null values.
   1838
   1839   tree_identifier *id = elt->ident ();
   1840
   1841   return id ? id->evaluate (*this).storable_value () : octave_value ();
   1842 }


I added a cout statement inside it and found that id is not null, so it's returning something, not an empty octave_value.

Arun Giridhar <arungiridhar>
Group Member
Fri 17 Mar 2023 05:57:28 PM UTC, comment #6: 

ok, so why is "t1.is_defined ()" now returning false?

Nicholas Jankowski <nrjank>
Group Member
Fri 17 Mar 2023 05:52:01 PM UTC, comment #5: 

The code in pt-eval.cc:

bool
tree_evaluator::is_logically_true (tree_expression *expr,
                                   const char *warn_for)
{
  bool expr_value = false;

  m_call_stack.set_location (expr->line (), expr->column ());

  octave_value t1 = expr->evaluate (*this);

  if (t1.is_defined ())
    return t1.is_true ();
  else
    error ("%s: undefined value used in conditional expression", warn_for);

  return expr_value;
}


Arun Giridhar <arungiridhar>
Group Member
Fri 17 Mar 2023 04:07:24 PM UTC, comment #4: 

maybe related. that's about performance of if(all(x)) versus if(x) which operates with an implied all.  the part that confuses me is why


if ([true true true]') ...


would be fine but


if ([true true true]' & [true true true]') ...


fails, when both internal parts should be the same before the 'if' has anything to do.

Nicholas Jankowski <nrjank>
Group Member
Fri 17 Mar 2023 03:45:13 PM UTC, comment #3: 
Arun Giridhar <arungiridhar>
Group Member
Fri 17 Mar 2023 02:23:48 PM UTC, comment #2: 

seeing the same on windows. updating platform and marking as confirmed. 




>> if (true & true), "true",else,"false",end
ans = true

>> if ([true,true] & [true,true]), "true",else,"false",end
error: if: undefined value used in conditional expression

>> if ([true,true]' & [true,true]'), "true",else,"false",end
error: if: undefined value used in conditional expression

>> if ([1,1] & [1,1]), "true",else,"false",end
error: if: undefined value used in conditional expression

>> if ([1,1] | [1,1]), "true",else,"false",end
error: if: undefined value used in conditional expression

>> a = [1,1]' | [1,1]'
a =

  1
  1

>> if (a), "true",else,"false",end
ans = true


so, something different is happening when evaluating the elementwise operator inside an if, such that if it results in a non-scalar, we get an undefined error.

Nicholas Jankowski <nrjank>
Group Member
Fri 17 Mar 2023 12:23:52 PM UTC, comment #1: 

A smaller bit of code that exhibits the issue:


if true(4,1) & true(4,1)
  disp('true');
end


which outputs on stable 8.x and dev 9.x


error: if: undefined value used in conditional expression
error: called from
    name_of_script_from_which_code_was_read at line 1 column 14


A.R. Burgers <arb>
Thu 16 Mar 2023 09:50:10 PM UTC, original submission:  

This bit of code is executed without error on octave-5.2.1 and matlab:


v = cell(4,1);
for i = 1 : 4
  v{i} = rand(10,3);
end
s = [1;3;5;7];
s1 = s <= 1
vc = cellfun('isclass', v, 'char')
vc & s1
if cellfun('isclass', v, 'char') & s <= 1
  disp('if branch true');
else
  disp('if branch false');
end


with this output:


if branch false


On both stable 8.x and dev 9.x execution is halted during evaluation of the if conditional with this error


error: if: undefined value used in conditional expression


A.R. Burgers <arb>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by arungiridhar
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by arb (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-04-11 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 8.2.0
    2023-03-20 jwe StatusConfirmed Ready For Test
        Planned ReleaseNone 8.2.0
    2023-03-17 arungiridhar Carbon-Copy- Added jwe
    2023-03-17 nrjank StatusNone Confirmed
        Operating SystemGNU/Linux Any

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code