Skip to content

Commit

Permalink
Proposed fix for 2017 nargout bug
Browse files Browse the repository at this point in the history
This tries to fix the bug #86 emerging in matlab 2017 editions (and maybe others) where the builtin numArgumentsFromSubscript is not behaving as expected, Instead of returning the correct nargout it basically returns numel(nigelObj) creating all sorts of problems, such as the too many output args when calling tankObj.nigelDash from base.

This solution relies on the number of declared args in the method declaration to determine nargout at this stage. This does not affect the effective number of output arguments which are still controlled by the number of variables on the left of an assignment. Bear in mind that this will effect the number of output args when called without an explicit assignment.
  • Loading branch information
Nabarb committed May 11, 2020
1 parent 5425644 commit baad50c
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions +nigeLab/@nigelObj/nigelObj.m
Original file line number Diff line number Diff line change
Expand Up @@ -547,21 +547,28 @@ function delete(obj)
n = builtin('numArgumentsFromSubscript',nigelObj,s,indexingContext);
end
case '.'
switch class(nigelObj)
case 'nigeLab.Block'
if ~isempty(nigelObj(1).Pars)
Ffields = nigelObj(1).Pars.Block.Fields;
idx = strcmpi(Ffields,s(1).subs);
if any(idx)
n = numel(nigelObj);
if ismethod(nigelObj,s(1).subs)
meta = metaclass(nigelObj);
methods = meta.MethodList;
thisMethod = methods(strcmp({methods.Name},s(1).subs));
n = numel(thisMethod.OutputNames);
else
switch class(nigelObj)
case 'nigeLab.Block'
if ~isempty(nigelObj(1).Pars)
Ffields = nigelObj(1).Pars.Block.Fields;
idx = strcmpi(Ffields,s(1).subs);
if any(idx)
n = numel(nigelObj);
else
n = builtin('numArgumentsFromSubscript',nigelObj,s,indexingContext);
end
else
n = builtin('numArgumentsFromSubscript',nigelObj,s,indexingContext);
end
else
otherwise
n = builtin('numArgumentsFromSubscript',nigelObj,s,indexingContext);
end
otherwise
n = builtin('numArgumentsFromSubscript',nigelObj,s,indexingContext);
end
end
otherwise
n = builtin('numArgumentsFromSubscript',nigelObj,s,indexingContext);
Expand Down

0 comments on commit baad50c

Please sign in to comment.