Mercurial > octave
changeset 23838:6e0fd7e3c262
Fix argument lookup in '+' package functions (Bug #51532).
* pt-eval.cc (tree_evaluator::visit_index_expression): Check to see if the
expression is a package. If it is, then indexing_object should be false.
* ov.h, ov-base.h, ov-classdef.cc (is_package): New method for checking if
object is a package. It passes information from cdef_meta_object.
* test/module.mk, test/bug-51532/module.mk, test/+package_bug51532/foo.m,
test/bug-51532.tst: Added test for the bug.
author | Piotr Held <pjheld@gmail.com> |
---|---|
date | Mon, 07 Aug 2017 15:05:19 -0700 |
parents | 551e4d1dd28f |
children | 724fe19b50dc |
files | libinterp/octave-value/ov-base.h libinterp/octave-value/ov-classdef.cc libinterp/octave-value/ov.h libinterp/parse-tree/pt-eval.cc test/bug-51532/+package_bug51532/foo.m test/bug-51532/bug-51532.tst test/bug-51532/module.mk test/module.mk |
diffstat | 8 files changed, 50 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base.h Mon Aug 07 08:29:39 2017 -0700 +++ b/libinterp/octave-value/ov-base.h Mon Aug 07 15:05:19 2017 -0700 @@ -373,6 +373,8 @@ virtual bool is_classdef_meta (void) const { return false; } virtual bool is_classdef_object (void) const { return false; } + + virtual bool is_package (void) const { return false; } virtual bool isjava (void) const { return false; }
--- a/libinterp/octave-value/ov-classdef.cc Mon Aug 07 08:29:39 2017 -0700 +++ b/libinterp/octave-value/ov-classdef.cc Mon Aug 07 15:05:19 2017 -0700 @@ -1018,6 +1018,8 @@ { object.meta_release (); } bool is_classdef_meta (void) const { return true; } + + bool is_package (void) const { return object.is_package(); } octave_function * function_value (bool = false) { return this; }
--- a/libinterp/octave-value/ov.h Mon Aug 07 08:29:39 2017 -0700 +++ b/libinterp/octave-value/ov.h Mon Aug 07 15:05:19 2017 -0700 @@ -591,6 +591,9 @@ bool is_classdef_object (void) const { return rep->is_classdef_object (); } + + bool is_package (void) const + { return rep->is_package (); } bool isobject (void) const { return rep->isobject (); }
--- a/libinterp/parse-tree/pt-eval.cc Mon Aug 07 08:29:39 2017 -0700 +++ b/libinterp/parse-tree/pt-eval.cc Mon Aug 07 15:05:19 2017 -0700 @@ -1339,13 +1339,16 @@ // // classname.static_function (args, ...); // - // then we'll just build a complete index list for one big subsref - // call. If the expression we are indexing is a classname, then - // base_expr_val will be an octave_classdef_meta object. - - bool indexing_object - = (base_expr_val.isobject () || base_expr_val.isjava () - || base_expr_val.is_classdef_meta ()); + // then we'll just build a complete index list for one big subsref call. + // If the expression we are indexing is a classname then base_expr_val will + // be an octave_classdef_meta object. + // If we have files in a +packagename folder, they will also be an + // octave_classdef_meta object, but we don't want to index them. + + bool indexing_object = ( base_expr_val.isobject () + || base_expr_val.isjava () + || (base_expr_val.is_classdef_meta () + && ! base_expr_val.is_package ())); std::list<octave_value_list> idx;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-51532/+package_bug51532/foo.m Mon Aug 07 15:05:19 2017 -0700 @@ -0,0 +1,3 @@ +function retval = foo (val) + retval = val; +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-51532/bug-51532.tst Mon Aug 07 15:05:19 2017 -0700 @@ -0,0 +1,23 @@ +## 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 for value returned from a +package function +%!test +%! r = package_bug51532.foo ("asdf"); +%! assert (ischar (r)); +%! assert (r, "asdf");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-51532/module.mk Mon Aug 07 15:05:19 2017 -0700 @@ -0,0 +1,5 @@ +bug_51532_TEST_FILES = \ + %reldir%/bug-51532.tst \ + %reldir%/+package_bug51532/foo.m + +TEST_FILES += $(bug_51532_TEST_FILES)
--- a/test/module.mk Mon Aug 07 08:29:39 2017 -0700 +++ b/test/module.mk Mon Aug 07 15:05:19 2017 -0700 @@ -57,10 +57,11 @@ include %reldir%/bug-50035/module.mk include %reldir%/bug-50716/module.mk include %reldir%/bug-51192/module.mk +include %reldir%/bug-51532/module.mk include %reldir%/bug-51599/module.mk include %reldir%/class-concat/module.mk +include %reldir%/classdef/module.mk include %reldir%/classdef-multiple-inheritance/module.mk -include %reldir%/classdef/module.mk include %reldir%/classes/module.mk include %reldir%/ctor-vs-method/module.mk include %reldir%/fcn-handle-derived-resolution/module.mk