bugGNU Octave - Bugs: bug #66271, subsref and subsasgn fail to...

 
 

bug #66271: subsref and subsasgn fail to receive .(integer) operator

Submitter:  Qianqian Fang <fangq>
Submitted:  Sat 28 Sep 2024 07:33:04 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  None Assigned to:  None
Originator Name:  Qianqian Fang Open/Closed:  * Open
Release:  * 9.1.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 30 Sep 2024 06:08:53 PM UTC, comment #4: 

I tested on the obj struct:


octave:1> obj = struct('key1', struct('subkey1',1, 'subkey2',[1,2,3]), 'subkey2', 'str');
octave:2> obj.('key1').('subkey2')(1)
ans = 1


Isn't the issue now in jdict's subsref?

Anonymous
Mon 30 Sep 2024 05:51:06 PM UTC, comment #3: 

@comment #2:
yields another error in Octave-10.0.0:

>> obj = struct('key1', struct('subkey1',1, 'subkey2',[1,2,3]), 'subkey2', 'str');
>> obj.key1.subkey3 = {8,'test',containers.Map('subsubkey1',0)};
>> jd = jdict(obj);
>> jd
jd =
  jdict object with properties:
      data: [1x1 struct]

>> jd.('key1').('subkey2')(1)
error: ismember: cell array of strings cannot be combined with a nonstring value
error: called from
    validsetargs at line 50 column 9
    ismember at line 121 column 4
    subsref at line 121 column 26


Philip Nienhuis <philipnienhuis>
Group Member
Mon 30 Sep 2024 05:11:26 PM UTC, comment #2: 

What about:


jd.('key1').('subkey2')(1)


Anonymous
Sat 28 Sep 2024 07:42:23 PM UTC, comment #1: 

a quick correction:

for .(1), what matlab passes to subsref/subsasgn was the following operator


struct('type','.', 'subs', 1)



Qianqian Fang <fangq>
Sat 28 Sep 2024 07:33:04 PM UTC, original submission:  

I am trying to write a general hierarchical data container, jdict, to provide a uniform access and modification interface for struct/containers.Map/dictionary data for both matlab and octave, the current code is at

https://github.com/fangq/jsonlab/blob/afce1de01e0c0e7deed687281bba10a190a86c40/jdict.m

for example, for a complex structure such as


obj = struct('key1', struct('subkey1',1, 'subkey2',[1,2,3]), 'subkey2', 'str');
obj.key1.subkey3 = {8,'test',containers.Map('subsubkey1',0)};

jd = jdict(obj);


I could use various ways to various ways to retrieve and modify sub-element values.

However, on MATLAB, my overloading subsref and subsasgn operators could also use .(i) to read and write element values in Octave.

For example, the below call using the above data

jd.('key1').('subkey2').(1)


is expected to return the 1st element of obj.key1.subkey2, which is 1, but Octave directly threw the following error without even calling either of these indexing operator functions


error: dynamic structure field names must be strings


In comparison, MATALB successfully pass the operator struct('type','()', 'subs', 1) to subsref or subsasgn operators, and allow me to read/write such values.

It appears that the interpreter is doing some error checking before passing on to subsref or subsasgn, but it seems more appropriate to handle this inside the indexing operators themselves.

The expected behavior is to allow accepting .(i) in a classdef's overloading subsref or subsasgn operators.

Qianqian Fang <fangq>

 

(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 fangq (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.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-5884.
    Corresponding source code