Mercurial > octave
changeset 23842:ff893e26aeeb
make calling parent class constructors work again (bug #51534)
* pt-eval.cc (tree_evaluator::visit_index_expression):
Handle calls to superclass constructors.
* test/bug-51534/module.mk, test/bug-51534/bug-51534.tst,
test/bug-51534/child_bug51534.m, test/bug-51534/parent_bug51534.m:
New files.
* test/module.mk: Update.
author | Piotr Held <pjheld@gmail.com> |
---|---|
date | Tue, 08 Aug 2017 18:18:01 -0400 |
parents | 3930c54f8462 |
children | a52eb3f210af |
files | libinterp/parse-tree/pt-eval.cc test/bug-51534/bug-51534.tst test/bug-51534/child_bug51534.m test/bug-51534/module.mk test/bug-51534/parent_bug51534.m test/module.mk |
diffstat | 6 files changed, 87 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc Tue Aug 08 11:55:59 2017 -0700 +++ b/libinterp/parse-tree/pt-eval.cc Tue Aug 08 18:18:01 2017 -0400 @@ -1370,9 +1370,11 @@ // Silently ignore extra output values. octave_value_list tmp_list - = base_expr_val.subsref (type.substr (beg, i-beg), idx, nargout); - - partial_expr_val = tmp_list.length () ? tmp_list(0) : octave_value (); + = base_expr_val.subsref (type.substr (beg, i-beg), + idx, nargout); + + partial_expr_val + = tmp_list.length () ? tmp_list(0) : octave_value (); if (! indexing_object) { @@ -1435,23 +1437,50 @@ p_dyn_field++; } - if (! idx.empty () && (! base_expr_val.is_function () - || base_expr_val.is_classdef_meta ())) + + // If ! idx.empty () that means we still have stuff to index otherwise + // they would have been dealt with and idx would have been emptied. + if (! idx.empty ()) { - try + // This is for +package and other classdef_meta objects + if (! base_expr_val.is_function () + || base_expr_val.is_classdef_meta ()) { - retval = base_expr_val.subsref (type.substr (beg, n-beg), idx, nargout); - - beg = n; - idx.clear (); + try + { + retval = base_expr_val.subsref (type.substr (beg, n-beg), + idx, nargout); + } + catch (octave::index_exception& e) + { + final_index_error (e, expr); + } } - catch (index_exception& e) // range problems, bad index type, etc. + else { - final_index_error (e, expr); + // FIXME: we want this to only be a superclass constructor + // call Should we actually make a check for this or are all + // other types of calls already dealt with? + + octave_function *fcn = base_expr_val.function_value (); + + if (fcn) + { + try + { + retval = fcn->call (*this, nargout, idx); + } + catch (octave::index_exception& e) + { + final_index_error (e, expr); + } + } } } - // This happens if... ?? + // FIXME: when can the following happen? In what case does indexing + // result in a value that is a function? Classdef method calls? + // Something else? octave_value val = (retval.length () ? retval(0) : octave_value ());
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-51534/bug-51534.tst Tue Aug 08 18:18:01 2017 -0400 @@ -0,0 +1,21 @@ +## Copyright (C) 2017 Piotr Held +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +%!test +%! a = child_bug51534 ('asd'); +%! assert (strcmp (a.prop, 'asd'));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-51534/child_bug51534.m Tue Aug 08 18:18:01 2017 -0400 @@ -0,0 +1,7 @@ +classdef child_bug51534 < parent_bug51534 + methods + function self = child_bug51534 (val) + self@parent_bug51534 (val); + endfunction + endmethods +endclassdef
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-51534/module.mk Tue Aug 08 18:18:01 2017 -0400 @@ -0,0 +1,6 @@ +bug_51534_TEST_FILES = \ + %reldir%/bug-51534.tst \ + %reldir%/parent_bug51534.m \ + %reldir%/child_bug51534.m + +TEST_FILES += $(bug_51534_TEST_FILES)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-51534/parent_bug51534.m Tue Aug 08 18:18:01 2017 -0400 @@ -0,0 +1,10 @@ +classdef parent_bug51534 < handle + properties + prop + endproperties + methods + function self = parent_bug51534 (val) + self.prop = val; + endfunction + endmethods +endclassdef
--- a/test/module.mk Tue Aug 08 11:55:59 2017 -0700 +++ b/test/module.mk Tue Aug 08 18:18:01 2017 -0400 @@ -58,6 +58,7 @@ include %reldir%/bug-50716/module.mk include %reldir%/bug-51192/module.mk include %reldir%/bug-51532/module.mk +include %reldir%/bug-51534/module.mk include %reldir%/bug-51599/module.mk include %reldir%/class-concat/module.mk include %reldir%/classdef/module.mk