bugGNU Octave - Bugs: bug #55766, properties function should not...

 
 

bug #55766: properties function should not return Hidden properties

Submitter:  Rik <rik5>
Submitted:  Fri 22 Feb 2019 07:04:28 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 15 Jun 2019 05:37:18 PM UTC, comment #8: 

I can also verify that there are no longer obtuse errors and that the test files in this bug report work.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Sat 15 Jun 2019 02:36:41 AM UTC, comment #7: 

The testprop4 example works for me with 792fe198c105 tip @


John W. Eaton <jwe>
Group administrator
Fri 14 Jun 2019 10:56:36 PM UTC, comment #6: 

@John - regarding:

The ordering of the properties is a separate issue that I think has already been reported.

Indeed, this has been reported in bug #55961, for which I have suggested a fix.

ImadES <ies>
Fri 14 Jun 2019 10:46:09 PM UTC, comment #5: 

I encounter a problem when the value for a classdef parameter is not a string, but a boolean.  Consider the following test class


classdef testprop4

  properties (Hidden = true)
    anotherhiddentestprop = 0;
  end

  properties (Hidden = false)
    notahiddentestprop = 0;
  end

end


In this case, the value for "Hidden" is a boolean.  When I run this code I get


octave:1> testprop4
ans =

  testprop4 object with properties:

error: octave_base_value::bool_value(): wrong type argument 'sq_string'


This does not occur for parameters such as "Access" which take a string value like "public".


(file #47101)

Rik <rik5>
Group administrator
Fri 14 Jun 2019 08:37:38 PM UTC, comment #4: 

Kai:  Thanks.

I checked in the following additional changes:

http://hg.savannah.gnu.org/hgweb/octave/rev/42efd1e986c7
http://hg.savannah.gnu.org/hgweb/octave/rev/792fe198c105

The ordering of the properties is a separate issue that I think has already been reported.

Marking as ready for test.

John W. Eaton <jwe>
Group administrator
Fri 14 Jun 2019 06:43:50 PM UTC, comment #3: 

For the classdef of comment #2 I changed the first property name  "testprob" to "testprob1" (bug #55767).  Then Matlab R2019a returns:


>> x = testprop;
>> properties (x)

Properties for class testprop:

    testprop1
    publictestprop
    notahiddentestprop

>> x

x =

  testprop with properties:

             testprop1: 0
        publictestprop: 0
    notahiddentestprop: 0


Kai Torben Ohlhus <siko1056>
Group Member
Fri 14 Jun 2019 06:07:32 PM UTC, comment #2: 

I used gdb to step through the compute_attribute_value function and "tw.evaluate (expr)" does evaluate the expression to be a octave_value object that is logical true.  So I think that part is working properly so your change there is not needed.  It's your change to cdef_class::cdef_class_rep::find_properties that has the effect of omitting the hidden property.  But I'm not sure that's the right place for this change.  Should that function return all public properties, even if they are hidden?  Also, you added the check inside the block where the property is not found directly, so we are then looking for inherited properties.  That doesn't seem quite right to me.  So I made the following change instead:

http://hg.savannah.gnu.org/hgweb/octave/rev/b15b71bcd679

Given the modified test case


classdef testprop

  properties
    testprop = 0;
  end

  properties (Access = public)
    publictestprop = 0;
  end

  properties (Access = protected)
    protectedtestprop = 0;
  end

  properties (Hidden)
    hiddentestprop = 0;
  end

  properties (Hidden = true)
    anotherhiddentestprop = 0;
  end

  properties (Hidden = false)
    notahiddentestprop = 0;
  end

end


I now see


octave:1> x = testprop;
octave:2> properties (x)
properties for class testprop:

  notahiddentestprop
  publictestprop
  testprop


so I believe that fixes the problem reported here.

However, I also see


octave:3> x
x =

  testprop object with properties:

      anotherhiddentestprop: [1x1 double]
             hiddentestprop: [1x1 double]
         notahiddentestprop: [1x1 double]
          protectedtestprop: [1x1 double]
             publictestprop: [1x1 double]
                   testprop: [1x1 double]


If the hidden and protected properties are also supposed to be hidden from this display, then I think that is a separate but similar change.  What does Matlab do for this new test case?

John W. Eaton <jwe>
Group administrator
Fri 14 Jun 2019 10:53:01 AM UTC, comment #1: 

Hi,

This very simple change:


diff -r 2d9decd77e58 libinterp/octave-value/cdef-class.cc
--- a/libinterp/octave-value/cdef-class.cc        Thu Jun 13 17:40:36 2019 -0500
+++ b/libinterp/octave-value/cdef-class.cc        Fri Jun 14 12:47:51 2019 +0200
@@ -434,6 +434,10 @@

         if (props.find (nm) == props.end ())
           {
+            octave_value hid = it->second.get ("Hidden");
+            if (hid.is_bool_scalar () && hid.bool_value ()) {
+              continue;
+            }
             if (mode == property_inherited)
               {
                 octave_value acc = it->second.get ("GetAccess");
@@ -824,6 +828,8 @@
               return std::string ("protected");
             else if (s == "private")
               return std::string ("private");
+            else if (s == "true")
+              return octave_value (true);
           }

         return tw.evaluate (expr);


has the desired effect. But something does not feel quite right. I wonder why


+            else if (s == "true")
+              return octave_value (true);


is required. I would have expected the function


  static octave_value
  compute_attribute_value (tree_evaluator& tw,
                           tree_classdef_attribute *t)


to return 'octave_value (true)' when reaching the line


        return tw.evaluate (expr);


with the tree_expression 'expr' corresponding to the string 'true'... I wonder why this is not the case, and whether there might be another prior problem at the parsing level, which lead me to have to explicitly handle the 'true' case...

ImadES <ies>
Fri 22 Feb 2019 07:04:28 PM UTC, original submission:  

According to documentation, Matlab does not return properties for which the "Hidden" attribute is true.

Code to reproduce:

Create a file testprop.m (attached) with this code


classdef testprop

        properties
                testprop = 0;
        end

        properties (Access = protected)
                protectedtestprop = 0;
        end

        properties (Hidden = true)
                hiddentestprop = 0;
        end

end


Then run


x = testprop
properties (x)



Rik <rik5>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #47101:  testprop4.m added by rik5 (156B - text/x-matlab)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by ies (Posted a comment)
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-06-15 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2019-06-14 rik5 Attached File- Added testprop4.m, #47101
    2019-06-14 jwe StatusIn Progress Ready For Test
    2019-06-14 jwe StatusNone In Progress

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code