Question: kernelopts('assertlevel'=2): causes problem when using objects

I found a big problem.

When adding kernelopts('assertlevel'=2): which I like to have it on all the time to catch (actual) errors, but now Maple server hangs then crashes on what should be no issue at all. 

This happens when I am using an object, which is used at global type. Here is a MWE

restart;

interface(warnlevel=4);
kernelopts('assertlevel'=2);

local ode_type:=module()
    option object;
    export ode;
    local ModuleLoad::static:=()->
           TypeTools:-AddType(':-ode_type', ode_type);
    ModuleLoad()       
end module:

A:=module()
  export foo:=proc()
    C:-foo();
  end proc;

  local B:=module()
    export foo:=proc()
      local ODE::ode_type;
      return ODE;
    end proc;
  end module;

  local C:=module()
    export foo:=proc()
      local the_ode::ode_type;  #THIS CAUSES the hang
                                #using the_ode::':-ode_type'; makes no difference
      #DEBUG
      the_ode:=B:-foo();
    end proc;
  end module;
end module;

There is nothing wrong with the above code as far as I can see. But now A:-foo(); crashes the Maple server.

If I change the line local the_ode::ode_type; to local the_ode; i.e. remove the type on the local variable, it works.

So assert thinks the type being returned is not ode_type

It also works if I remove the assert and keep the type there. Like this

restart;

interface(warnlevel=4);

local ode_type:=module()
    option object;
    export ode; 
    local ModuleLoad::static:=()->
           TypeTools:-AddType(':-ode_type', ode_type);
    ModuleLoad()       
end module:

A:=module()
  export foo:=proc()
    C:-foo();
  end proc;

  local B:=module()
    export foo:=proc()
      local ODE::ode_type;
      return ODE;
    end proc;
  end module;

  local C:=module()
    export foo:=proc()
      local the_ode::ode_type;  #NOW IT WORKS
      the_ode:=B:-foo();
    end proc;
  end module;
end module;

In my actual code, when I remove the kernelopts('assertlevel'=2); I do get correct final output. So it is not like I am bypassing some wrong code or something. The code works as expected.

Now now I have two choices, either remove  kernelopts('assertlevel'=2); or remove the type from the defintion of the local variables, when the type of object defined as above.

edit

another version below. When I copied the code above from my .mpl files to the worksheet to make a MWE, there was a local next to the object module (because that is how it is in my main code), and I did not notice it at first.

When I removed it to make new MWE in the worksheet, an error still shows up. But now Maple server do not hang/crash but it still does not like the assignment being made. So here is another version

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):


ode_type:=module()  #note that local ode_type:=module()  crashes Maple.
    option object;
    export ode; #can be list      
    local ModuleLoad::static:=()->
           TypeTools:-AddType(':-ode_type', ode_type);
    ModuleLoad()       
end module:

A:=module()
  export foo:=proc()
    C:-foo();
  end proc;

  local B:=module()
    export foo:=proc()
      local ODE::ode_type;
      return ODE;
    end proc;
  end module;

  local C:=module()
    export foo:=proc()
      local the_ode::ode_type;
      #DEBUG();
      the_ode:=B:-foo();
    end proc;
  end module;
end module;

And now A:-foo(); do not crash the server, but still gives error

     Error, (in foo) assertion failed in assignment to the_ode, expected ode_type, got ODE

Why? since ODE is of type ode_type, and I am returning. Can one not return Object like this? 

Is there something I am doing wrong?

 

 

Please Wait...