bugGNU Octave - Bugs: bug #52989, classdef: missing error messages...

 
 

bug #52989: classdef: missing error messages on multiply defined properties

Submitter:  A.R. Burgers <arb>
Submitted:  Sat 27 Jan 2018 10:34:25 PM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 11 Mar 2019 06:59:21 PM UTC, comment #2: 

refresh of this patch for octave-6.x.x:


diff -r 62c1443babd8 libinterp/octave-value/cdef-class.cc
--- a/libinterp/octave-value/cdef-class.cc      Sun Mar 10 17:02:27 2019 -0700
+++ b/libinterp/octave-value/cdef-class.cc      Mon Mar 11 19:57:31 2019 +0100
@@ -1062,6 +1062,8 @@
                 for (auto& prop_p : *pb_p->element_list ())
                   {
                     std::string prop_name = prop_p->ident ()->name ();
+                    if (retval.find_property(prop_name).ok())
+                       error ("property %s already defined", prop_name.c_str());

                     cdef_property prop = cdm.make_property (retval, prop_name);


A.R. Burgers <arb>
Sun 28 Jan 2018 09:30:08 PM UTC, comment #1: 

Here is a tentative patch, with which produces an error when an attempt is made to create a property when a property with that name is already present in the class or any of the superclasses:


diff -r d58543eb53e9 libinterp/octave-value/ov-classdef.cc
--- a/libinterp/octave-value/ov-classdef.cc     Fri Jan 26 00:11:11 2018 -0500
+++ b/libinterp/octave-value/ov-classdef.cc     Sun Jan 28 22:25:37 2018 +0100
@@ -2756,6 +2765,8 @@
               for (auto& prop_p : *pb_p->element_list ())
                 {
                   std::string prop_name = prop_p->ident ()->name ();
+                 if (retval.find_property(prop_name).ok())
+                   error ("property %s already defined", prop_name.c_str());

                   cdef_property prop = cdm.make_property (retval, prop_name);


A.R. Burgers <arb>
Sat 27 Jan 2018 10:34:25 PM UTC, original submission:  

octave happily parses this class:


classdef zz2
    properties
        p1
        p1
    end
    properties (Dependent)
        p1
    end
    methods
        function val = f(obj)
            val = 'f';
        end
    end
end


A side effect of the multiply defined properties is that method f can not be found: the next script


zz2_i = zz2;
f = zz2_i.f

gives this error message:

+verbatim+
error: subsref: unknown method or property: f
error: called from
    run_zz2 at line 2 column 3


Also octave allows the same property name in a class and a superclass:


classdef zz < zzs
    properties
        p1 = 2;
    end
end



classdef zzs
    properties
        p1 = 1;
    end
end


which results on execution of this script


zz_i = zz;
p1 = zz_i.p1


in


p1 =  2


Is the case for both stable and dev.
I didn't find this reported in an earlier bug report, but can hardly imagine this has gone unnoticed to date.


A.R. Burgers <arb>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by arb (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.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-23 mmuetzel CategoryInterpreter Classdef

    Back to the top

    Powered by Savane 3.14-8eb0.
    Corresponding source code