bugGNU Octave - Bugs: bug #58695, Array is left empty if an element...

 
 

bug #58695: Array is left empty if an element is a function call returning nothing

Submitter:  Fernando <tutissanalio>
Submitted:  Fri 03 Jul 2020 10:41:24 AM UTC
   
 
Category:  Interpreter Severity:  4 - Important
Priority:  7 - High Item Group:  Missed Error or Warning
Status:  Fixed Assigned to:  jwe
Originator Name:  Open/Closed:  * Closed
Release:  * 6.0.90 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 10 Jul 2020 11:01:55 PM UTC, comment #19: 

Verified fix, closing report

Rik <rik5>
Group administrator
Thu 09 Jul 2020 10:23:51 PM UTC, comment #18: 

jwe, thank you very much for taking into account my small contribution. I hope I can make more contributions.

Fernando <tutissanalio>
Thu 09 Jul 2020 05:53:19 PM UTC, comment #17: 

I pushed two more changes for this bug:

http://hg.savannah.gnu.org/hgweb/octave/rev/ac7ab2a9018e
http://hg.savannah.gnu.org/hgweb/octave/rev/66397e171801

I have a draft patch to make function evaluations throw errors if functions are called with too many inputs or requesting too many outputs.  It appears to work properly for the simple tests like those from comment #11, but it causes many failures in Octave's test suite:


Summary:

  PASS                            15771
  FAIL                              269
  REGRESSION                         23
  XFAIL (reported bug)               28
  SKIP (missing feature)             37
  SKIP (run-time condition)          14


I haven't checked in to any of these problems yet.  I suspect they are due to being somewhat sloppy about the number of inputs and outputs for various functions, like defining graphics callback functions with fewer inputs than are provided when they are called (if they are not used in the function anyway, then there is no real error, so...).  In any case, I think it is best to make this change on default rather than stable.  I'll discuss further on the maintainers list.

John W. Eaton <jwe>
Group administrator
Thu 09 Jul 2020 03:17:46 AM UTC, comment #16: 

I would favor more Matlab compatibility in this case, too, as pointed out on the mailing-list.

   https://lists.gnu.org/archive/html/octave-maintainers/2020-07/msg00022.html

First I thought this one was fixed alongside with bug #58686, but now I see the slight difference, if the function has no return value at all, no error is thrown in some cases.


>> function f1 (), end
>> function f2 (), 1; end
>> f1
>> f2
>> x = f1
error: value on right hand side of assignment is undefined
>> x = f2
error: value on right hand side of assignment is undefined
>> [1, f1, 2]
ans =

   1   2

>> [1, f2, 2]
ans =

   1   2


I want to see errors or warnings if I do stupid things 😊 And assigning something to an array, where it is impossible to include anything, looks like a programming error or an undesired/unexpected behavior to me.

Kai Torben Ohlhus <siko1056>
Group Member
Wed 08 Jul 2020 04:34:12 PM UTC, comment #15: 

I would stay as compatible to Matlab as possible. So, my vote is for changing both things.

Fernando <tutissanalio>
Wed 08 Jul 2020 04:14:24 PM UTC, comment #14: 

Thanks for the info.

For functions defined without a list of outputs and called in a context where nargout would be greater than zero, then I think the original intent in Octave was to allow the call but fail or warn or attempt to do something reasonable (if possible) when no outputs are created.  So I could see a reasonable argument made for allowing a function like this to return an empty comma-separated list, similar to what a.x does for an empty struct array.  But it might also be simpler to just have the function evaluation code always fail if nargout is greater than the number of declared outputs.

Similarly, I think Matlab throws an error if a function is called with more inputs than can possibly be used but Octave allows it.

Maybe it is time for both of these things to be changed?

John W. Eaton <jwe>
Group administrator
Wed 08 Jul 2020 02:58:00 PM UTC, comment #13: 

Sorry, in comment #12 I forgot two sentences. As before, this is Matlab 2020a:


>> f1
>> f2


So, these two sentences did not return anything and did not throw any error.


Fernando <tutissanalio>
Wed 08 Jul 2020 02:52:24 PM UTC, comment #12: 

Here is the output to those sentences (I had to define functions f1 and f2 in separe files, as Matlab does not allow function definitions from the command prompt):


>> x=f1
Error using f1
Too many output arguments.

>> x=f2
Error using f2
Too many output arguments.

>> [1, f1, 2]
Error using f1
Too many output arguments.

>> [1, f2, 2]
Error using f2
Too many output arguments.


Thank you very much. Of course you can use my full name, which is Fernando Alvarruiz.

Fernando <tutissanalio>
Wed 08 Jul 2020 02:17:08 PM UTC, comment #11: 

Oh, I see.

I think your change is the right thing to do, but we were already returning an empty octave_value_list in this case.   Your change makes the dot indexing operation return an empty comma-separated list instead.

We still have the issue of what functions without return lists should be creating.  Currently, they also create empty octave_value_list objects.

What does Matlab do for things like the following?


function f1 (), end
function f2 (), 1; end
f1
f2
x = f1
x = f2
[1, f1, 2]
[1, f2, 2]


With this info I think I can also make Octave's behavior consistent in these cases.

I'd also like to credit you for this change.  Can I use your full name for that?

John W. Eaton <jwe>
Group administrator
Wed 08 Jul 2020 01:09:18 PM UTC, comment #10: 

I think undefined values can be avoided, and should be errors when detected in matrix lists. The problem here, in my opinion, is that x.a should return an empty octave_value_list, instead of an undefined value. I attach a simple patch for your consideration.

(file #49449)

Fernando <tutissanalio>
Wed 08 Jul 2020 12:17:30 PM UTC, comment #9: 

I pushed the following additional change to fix the real problem of undefined values in matrix lists.

http://hg.savannah.gnu.org/hgweb/octave/rev/c318254c9f01

My assumption earlier was that we should (could?) avoid generating any undefined values, but an empty structure reference like the one in bug #58728 or a functions like


function f (), end


will generate undefined values in these contexts that we can't avoid.

John W. Eaton <jwe>
Group administrator
Wed 08 Jul 2020 07:52:18 AM UTC, comment #8: 

It works. Thank you!

Fernando <tutissanalio>
Wed 08 Jul 2020 01:34:16 AM UTC, comment #7: 

I pushed the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/ea5a632b2553

We could probably improve the error messages in the future, but at least now I think the behavior is correct.

Instead of the behavior of previous versions of Octave, it is probably best to not allow functions to return undefined values.

John W. Eaton <jwe>
Group administrator
Sat 04 Jul 2020 03:51:33 PM UTC, comment #6: 

I noticed the issue the day I published this bug, but it could have been there much before that.

Fernando <tutissanalio>
Sat 04 Jul 2020 12:41:56 PM UTC, comment #5: 

@Fernando: You are right.  I reverted the major change of bug #58686 and the error is still the same.

Do you recall since about when you had this issue?

Kai Torben Ohlhus <siko1056>
Group Member
Sat 04 Jul 2020 10:45:49 AM UTC, comment #4: 

Instead of saying "list" and "item" in the bug title and description, I should have said "vector" and "element". Sorry for that.


Fernando <tutissanalio>
Fri 03 Jul 2020 04:06:08 PM UTC, comment #3: 

Oh I am sorry, now I understand.  I was too focused that Matlab errors.  This needs indeed to be fixed!

Kai Torben Ohlhus <siko1056>
Group Member
Fri 03 Jul 2020 04:03:16 PM UTC, comment #2: 

Sorry for not specifying the output. In Matlab R2020a, the stated error message is displayed and no assignment takes place.

I think Octave (6.0.90) is clearly not compatible with Matlab, because Octave does not report any error and it does assign something (an empty list).

Fernando <tutissanalio>
Fri 03 Jul 2020 03:32:47 PM UTC, comment #1: 

Thank you for your report.  Can you be precise, what the output of Matlab R2020a is?  In R2020b, I receive for your example the stated error and no assignment happens.

Thus Octave seems perfectly Matlab compatible.  Personally, I favor this error too, as no values get ignored unnoticed.

Is there anything left to do?

Kai Torben Ohlhus <siko1056>
Group Member
Fri 03 Jul 2020 10:41:24 AM UTC, original submission:  

Checking bug #58686 I found the following incorrect behaviour in Octave 7.0.0 (hg id: d5311ca8f945):


octave:1> [2,do_nothing(3),5,3]
ans = [](0x0)


where do_nothing is a function that.. well, does nothing:


function retval = do_nothing(n)
end


The same in Octave 4.2.2:

octave:1> [2,do_nothing(3),5,3]
warning: do_nothing: some elements in list of return values are undefined
warning: called from
    do_nothing at line 2 column 1
ans =
   2   5   3


The same in Matlab 2020a:

>> [2,do_nothing(3),5,3]
Output argument "retval" (and maybe others) not assigned during call to "do_nothing".


Fernando <tutissanalio>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #49449:  bug58695.patch added by tutissanalio (1KiB - text/x-patch)

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

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 siko1056 (Posted a comment)
  • -email is unavailable- added by tutissanalio (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 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-07-10 rik5 StatusReady For Test Fixed
        Assigned toNone jwe
        Open/ClosedOpen Closed
    2020-07-08 tutissanalio Attached File- Added bug58695.patch, #49449
    2020-07-08 jwe Dependencies- bugs #58728 is dependent
    2020-07-08 jwe StatusConfirmed Ready For Test
    2020-07-04 siko1056 SummaryList is left empty if an item is a function call returning nothing Array is left empty if an element is a function call returning nothing
    2020-07-03 siko1056 Severity3 - Normal 4 - Important
        Priority5 - Normal 7 - High
        StatusNeed Info Confirmed
    2020-07-03 siko1056 StatusNone Need Info
        Releasedev 6.0.90

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code