bugGNU Octave - Bugs: bug #51633, Empty indexing of struct returns...

 
 

bug #51633: Empty indexing of struct returns empty struct array

Submitted by:  Piotr Held <jsoh425>
Submitted on:  Mon 31 Jul 2017 07:05:59 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: FixedAssigned to: None
Originator Name: Piotr HeldOpen/Closed: Closed
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Fri 11 Aug 2017 03:26:04 PM UTC, comment #10:

This was a simple fix. Unlike other data types, the struct do_index_op function was not checking the length of the index list for the special case where it was 0 (empty). I changed that and added a test for it here http://hg.savannah.gnu.org/hgweb/octave/rev/1b232c0c19e6.

I also checked the other data types and they seem to work, except possibly for objects where the subsref routine is often overloaded. I'll ask a question about that on the Maintainer's list.

Rik <rik5>
Project Administrator
Mon 07 Aug 2017 03:51:53 PM UTC, comment #9:

Marking as confirmed. The issue seems to be that an empty indexing expression for structs is interpreted as indexing with a null array.

Sample Code:

Conversely, for Arrays no index expression means perform no indexing operation at all.

Rik <rik5>
Project Administrator
Wed 02 Aug 2017 06:31:34 PM UTC, comment #8:

for reference, Matlab 2017 output for Dan's comment #6:

Nicholas Jankowski <nrjank>
Tue 01 Aug 2017 10:26:17 PM UTC, comment #7:

jwe: I'm sorry my reponse wasn't more precise.

I agree with Dan Sebald 'x()' should be the same as 'x'.

To be more precise we have:

So in Matlab assert passes and:

in Octave it fails and:

Piotr Held <jsoh425>
Tue 01 Aug 2017 07:09:59 PM UTC, comment #6:

It sounds to me like x() should always be the same as plain x. In Octave,

In the vector case, 'a()' is the same as 'a'... not 'a(1)'. So for consistency, I would think that 'b()' should print out whatever 'b' prints out--which isn't necessarily the same as what 'b(1)' prints out.

Dan Sebald <sebald>
Tue 01 Aug 2017 06:51:45 PM UTC, comment #5:

Sorry, I'm just really confused now by the description of what Matlab is doing.

John W. Eaton <jwe>
Project Administrator
Tue 01 Aug 2017 12:33:41 AM UTC, comment #4:

It is true of double, char, int32, classdef. So

All work, both in Matlab and in Octave. As far as I can tell only struct doesn't.

Piotr Held <jsoh425>
Mon 31 Jul 2017 11:24:06 PM UTC, comment #3:

Is this true of all structs or just scalar structs?

Is this true of all scalar objects?

John W. Eaton <jwe>
Project Administrator
Mon 31 Jul 2017 08:45:01 PM UTC, comment #2:

I mean that for Matlab the code would execute fine. What I meant by the equivalency is that:

for Matlab.

And for Octave it isn't, as your example clearly shows.

Piotr Held <jsoh425>
Mon 31 Jul 2017 08:33:57 PM UTC, comment #1:

I'm not following what is meant by "For Matlab it is equivalent to a(1)". "a()" in Octave is the same as "a(1)" in Matlab? Is the following what you mean?

Dan Sebald <sebald>
Mon 31 Jul 2017 07:05:59 PM UTC, original submission:

I apologize if this has been submitted earlier, I couldn't find it.

So with this code:
Returns
For Matlab it is equivalent to:

This might seem trivial in most cases, but if you had a class name 'class1' and property name 'prop1'. If 'prop1' happens to be a struct your (somewhat improper) code:
Fails when you try to assign something to a field of that struct.

Should I try to fix this, or is the code example I gave just "bad coding" and it's better if the code doesn't execute?

Piotr Held <jsoh425>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by nrjank (Posted a comment)
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by sebald (Posted a comment)
  • -unavailable- added by jsoh425 (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 11 Aug 2017 03:26:04 PM UTCrik5StatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Mon 07 Aug 2017 03:51:53 PM UTCrik5StatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1