Question: on return type of function when using user defined type

When making a function and using the return type, I found Maple is not catching the case when the function returns wrong type.

Actually there are two issues in this example I like to ask about. First, here is the example

restart;
kernelopts(assertlevel):=2;
TypeTools:-AddType(type_A, record(x::integer)):

foo:=proc( A::type_A ) ::type_A;  #this is what return type should be
     print( type(A,'type_A')); #this prints TRUE
     A:-x :=1.5; #opps, wrong type, changes type of record now!
     print( type(A,'type_A')); #This now prints FALSE
     return A;
end proc:

A:=Record('x' = 1);
B:=foo(A):
eval(B)

The call to foo() goes through as expected since type is correct.

First issue: Inside the function doing A:-x :=1.5;  changed the type of record now, since is supposed to be integer and now become real. Is there a way to have Maple detect this at run time?

Second issue: The function was defined to return type_A  but due to this overwriting the field of the record by wrong value, it is no longer type_A  (the print now says false). But why Maple did not detect this? Since the function is defined to only return type_A ?

Is it possible to change the code above to catch these type mistakes I made?

Please Wait...