[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #59737] end keyword not passed to oveloaded su
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #59737] end keyword not passed to oveloaded subsfef function within custom classdef |
Date: |
Sun, 20 Dec 2020 00:01:21 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0 |
URL:
<https://savannah.gnu.org/bugs/?59737>
Summary: end keyword not passed to oveloaded subsfef function
within custom classdef
Project: GNU Octave
Submitted by: None
Submitted on: Sun 20 Dec 2020 05:01:19 AM UTC
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Incorrect Result
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Release: 6.1.0
Discussion Lock: Any
Operating System: Any
_______________________________________________________
Details:
= Problem Description =
The end keyword is not passed to an overloaded subsref function.
= How to reproduce =
Copy the following into cantuseend.m
classdef cantuseend
properties
value;
endproperties
methods
function obj=cantuseend(a)
obj.value=a;
endfunction
function obj=subsref(a,s)
if strcmp(s.type,"()")
obj=cantuseend(subsref(a.value,s));
s
else
obj=builtin('subref',a,s);
end
endfunction
function display(a)
disp(a.value);
endfunction
function varargout=size(a,varargin)
nout=nargout;
if nout<=1
varargout={size(a.value,varargin{:})};
else
varargout=nthargout(1:max(nargout,1),@size,a.value,varargin{:});
end
end
function v=columns(a)
v=columns(a.value);
endfunction
function v=rows(a)
v=rows(a.value);
endfunction
function v=numel(a,varargin)
v=numel(a.value,varargin{:});
endfunction
function v=ndims(a)
v=ndims(a.value);
end
function v=length(a)
v=length(a.value);
end
endmethods
endclassdef
At the command prompt type:
q=cantuseend(rand(4,1))
q(2:4)%works as expected
q(2:end)%Expected the above output got 1 by 0 empty result
q(end)%returns the first element not the last
I am printing what is in the sub-reference structure every time the function
is called. For the second call I get an empty subs for the third call I get
the number one within subs.
= Suggested Fixes =
Pass through a token which can be interpreted as end - even better if this
token can be interpreted by builtin functions.
Use the size method (or another method, document which one) of the classdef
object to convert end into the correct index. Give an error if the size method
has not been overloaded.
Raise an error telling the user end is not supported for custom objects and
tell the user to pass the last index of the object instead of end. This can't
currently be done within an overloaded subsref function as the input looks
valid. Without an error being thrown this bug could result in undetected
incorrect results and code that is very difficult to debug because without
looking at each output and finding this bug the code will look correct.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?59737>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #59737] end keyword not passed to oveloaded subsfef function within custom classdef,
anonymous <=