This is a much simplified version of a problem I am seeing. I think I have to remove all the coerce code I added as it seems to have problems.
Made an object with constructor that take an optional argument. These optional arguments use coerce to convert different types on one type of list.
I have another proc foo() that is called with these arguments, also same optional ones, and it then creates the object passing these arguments to it.
The problem is that if foo() is called with an optional argument itself, which will default to empty list [], I am not able to create the object now, when doing ':-ic'=ic since debugger gives
Error, invalid input: too many and/or wrong type of arguments passed to ModuleCopy; first unused argument is [] = []
Even though I made sure to pass the optional argument using ':-name'=value.
The strange thing is that this only shows in the debugger. i.e. when typing the command in the debugger window. But in my application, it does not work inside the debugger and outside since it is much more complicated setup. This is the simplest example I could make to show the same error in the debugger.
A small example will show the problem.
restart;
A:=module()
option object;
export ode;
export ic;
export ModuleCopy::static:=proc(_self, proto::A, ode::`=`,
{ ic::coerce( (ic::list(`=`))->ic,
(ic::set(`=`))->[ic[]],
`:-NoUserValue`):=[]
},$)
print("ode=",ode);
print("ic=",ic);
end proc;
end module;
foo:=proc(ode::`=`,{ ic::coerce( (ic::list(`=`))->ic,
(ic::set(`=`))->convert(ic,list),
`:-NoUserValue`):=[]
},$)
local o;
DEBUG();
o:=Object(A,ode,':-ic'=ic);
end proc:
# and now
foo(diff(y(x),x)=1)
Now the debugger window shows at the line above just before calling the object constructor. This is what happens next
But if I click continue it does not produce an error and actually works. (in my main application, with similar setup, it gives an exception).
If I can figure why debugger gives this error, may be that will help me figure my more complicated setup. I know if I do not use coerce, the debugger error goes away. Here is a version without coerce, and it works
restart;
A:=module()
option object;
export ode,ic;
export ModuleCopy::static:=proc(_self, proto::A, ode::`=`, { ic::list(`=`):=[] })
print("ode=",ode);
print("ic=",ic);
end proc;
end module;
A := Object<<2457889631168>>
foo:=proc(ode::`=`, { ic::list(`=`):=[]})
local o;
DEBUG();
o:=Object(A,ode,':-ic'=ic);
end proc:
#now do
foo(diff(y(x),x)=1)
Now the debugger window comes up, but now see the difference:
No error! even though `ic` was [] in this case also, like the first example.
So for now, I will remove all the coerce code just to get my application to work again even though I like it, but it seems to cause a problem.
question: What the first example above given an error in the debugger?
Notice this error only shows up when using a module of type object.
Update
This is just to confirm that removing the coerce API and replacing it back as it was with traditional optional arguments as in the second example above the exception went away. My code is way too large to post here, but that is the only difference I have. I think there is a problem using coerce with Object constructor calling somewhere. But I am OK now, and able to continue work.