bugGNU Octave - Bugs: bug #60489, Erroneous duplicate method...

 
 

bug #60489: Erroneous duplicate method declaration in classdef file does not generate an error

Submitted by:  PIERRE LABRECHE <pierre5018>
Submitted on:  Fri 30 Apr 2021 09:40:24 PM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  PIERRE LABRECHE Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon 03 May 2021 01:42:00 AM UTC, comment #2: 

Just an observation, in classdef files there can be multiple functions with the same name, as long as they have different calling signatures.  My guess is that it was simplest to just disable duplicate method validation when classdef was first implemented, and no one got around to improving things.

Rik <rik5>
Project Administrator
Mon 03 May 2021 01:31:58 AM UTC, comment #1: 

Confirmed.  Changing Summary to be more specific about the problem (classdef methods).

For regular functions, the interpreter is smart enough to issue a warning.  For this code (attached as tst_fcn_dup.m)

function tst_fcn_dup ()
  subfcn1 ();
  subfcn2 ();
endfunction

function subfcn1 ()
  disp ("First definition of subfcn1");
endfunction

function subfcn2 ()
  disp ("calling subfcn2");
endfunction

function subfcn1 ()
  disp ("Second definition of subfcn1");
endfunction

the error message when run is

error: parse error near line 14 of file /home/rik/wip/Projects_Mine/octave-dev/tst_fcn_dup.m

  duplicate subfunction or nested function name

>>> function subfcn1 ()
            ^

(file #51365)

Rik <rik5>
Project Administrator
Fri 30 Apr 2021 09:40:24 PM UTC, original submission:  

Octave fails to report an error or a warning when a class declares the same method twice.

Example:

classdef toto
  properties
    a
  endproperties

  methods
    function obj = toto (a)
      obj.a = a
    endfunction

    # double declaration is not flagged as error or warning
    function obj = toto (a)
      obj.a = 50 ;
    endfunction

  endmethods
endclassdef

PIERRE LABRECHE <pierre5018>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #51365:  tst_fcn_dup.m added by rik5 (272B - 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 rik5 (Updated the item)
  • -email is unavailable- added by pierre5018 (Submitted the item)
  • -email is unavailable- added by pierre5018
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-05-03 rik5 Attached File- => Added tst_fcn_dup.m, #51365
        StatusNone => Confirmed
        Release6.2.0 => dev
        Operating SystemMicrosoft Windows => Any
        SummaryErroneous duplicate declaration does not generate an error => Erroneous duplicate method declaration in classdef file does not generate an error
    2021-04-30 pierre5018 Carbon-Copy- => Added pierrelabreche@gmail.com

    Back to the top


    Powered by Savane 3.6