Question: New problem using suggested solution in new setup with _self and Object

The suggested solution in the answer https://mapleprimes.com/questions/234325-Use-Of-self--Inside-Object-Constructor  worked OK in the setup shown in that question.

But it does not work when putting the constructor inside overload

Here is an example where it works (i.e. by removing the type from _self as suggested in the above answer)

restart;

person:=module()
    option object;
    local name::string:="";

    #notice no _self::person, just _self
    export ModuleCopy::static:= proc( _self, proto::person, the_name::string, $ )            
           name:= the_name;
    end proc;

end module;


p:=Object(person,"me")

The above works. But since I have different constructors, once I put the above inside overload, using the same exact syntax, now the error comes back

restart;

person:=module()
    option object;
    local name::string:="";

    export ModuleCopy::static:= overload( 
    [
       proc( _self, proto::person, the_name::string, $ ) option overload;           
           name:= the_name;
      end proc
    ]);

end module;
             

p:=Object(person,"me")

Error, static procedure `ModuleCopy` refers to non-static local or export `name::string` in surrounding scope

I did not expect that using overload will cause any change to how it behaves. Is this a bug?

Below is worksheet also.

interface(version);

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

restart;

person:=module()
    option object;
    local name::string:="";

    export ModuleCopy::static:= proc( _self, proto::person, the_name::string, $ )            
           name:= the_name;
    end proc;

end module;

_m2950059551392

p:=Object(person,"me")

_m2950172920000

restart;

person:=module()
    option object;
    local name::string:="";

    export ModuleCopy::static:= overload(
    [
       proc( _self, proto::person, the_name::string, $ ) option overload;           
           name:= the_name;
      end proc
    ]);

end module;

_m2950059551392

p:=Object(person,"me")

Error, static procedure `ModuleCopy` refers to non-static local or export `name::string` in surrounding scope

 

Download OO_version.mw

Please Wait...