# HG changeset patch
# User Piotr Held <pjheld@gmail.com>
# Date 1502143519 25200
#      Mon Aug 07 15:05:19 2017 -0700
# Node ID c464ac7afdf5346d47246d03b85aef482a7e329b
# Parent  551e4d1dd28fc00024f068c9784a1539c390e750
Fixed argument lookup in '+' package functions (Bug #51532)

* pt-eval.cc: inside tree_evaluator::visit_index_expression added a check to se if the expression is a package. If it is, then indexing_object should be false.
* ov-base.h, ov-classdef.cc, ov.h: created new method 'is_package ()' for checking if object is a package. It passes information from cdef_meta_object.
* module.mk, bug-51532/module.mk, +package_bug51532/bar.m, bug-51532.tst: Added test for the bug. Enter commit message.

diff -r 551e4d1dd28f -r c464ac7afdf5 libinterp/octave-value/ov-base.h
--- 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; }
 
diff -r 551e4d1dd28f -r c464ac7afdf5 libinterp/octave-value/ov-classdef.cc
--- 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; }
 
diff -r 551e4d1dd28f -r c464ac7afdf5 libinterp/octave-value/ov.h
--- 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 (); }
diff -r 551e4d1dd28f -r c464ac7afdf5 libinterp/parse-tree/pt-eval.cc
--- 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
@@ -1342,10 +1342,15 @@
     // 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.
+    // 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. 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_classdef_meta ()
+             && ! base_expr_val.is_package ()));
 
     std::list<octave_value_list> idx;
 
diff -r 551e4d1dd28f -r c464ac7afdf5 test/bug-51532/+package_bug51532/bar.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-51532/+package_bug51532/bar.m	Mon Aug 07 15:05:19 2017 -0700
@@ -0,0 +1,3 @@
+function ret = bar (val)
+  ret = val;
+end
diff -r 551e4d1dd28f -r c464ac7afdf5 test/bug-51532/bug-51532.tst
--- /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,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/>.
+
+%% Testing whether I can get a return value from a package function
+%!test
+%! assert(package_bug51532.bar('asd') == 'asd')
diff -r 551e4d1dd28f -r c464ac7afdf5 test/bug-51532/module.mk
--- /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/bar.m
+
+TEST_FILES += $(bug_51532_TEST_FILES)
diff -r 551e4d1dd28f -r c464ac7afdf5 test/module.mk
--- a/test/module.mk	Mon Aug 07 08:29:39 2017 -0700
+++ b/test/module.mk	Mon Aug 07 15:05:19 2017 -0700
@@ -58,6 +58,7 @@
 include %reldir%/bug-50716/module.mk
 include %reldir%/bug-51192/module.mk
 include %reldir%/bug-51599/module.mk
+include %reldir%/bug-51532/module.mk
 include %reldir%/class-concat/module.mk
 include %reldir%/classdef-multiple-inheritance/module.mk
 include %reldir%/classdef/module.mk
