Closed DanielW0108 closed 1 year ago
This is the expected behaviour of Asymptote's function signature matching algorithm, as described here:
https://asymptote.sourceforge.io/doc/Default-arguments.html
See also https://asymptote.sourceforge.io/doc/Named-arguments.html
In your example, the int argument can be cast to a pair, and so it assigned to the first argument. You then need to supply a second int since the second argument does not have a default value.
Perhaps what you really intended was
int f (explicit pair foo=(0,0), int x) {
return x;
};
Ah, I wasn't aware that ints can be implicitly cast to pairs - makes sense when treating pairs as complex numbers, but unintuitive when they're mostly being used as coordinates. Thanks for the response.
Minimal example:
Trying to compile this gives the following error:
cannot call 'int f(pair foo=<default>, int x)' with parameter '(int)'
Calling
f(x = 1)
compiles, as does swapping the order of the parameters to this:This seems to happen whenever
x
has a type that could appear inside a pair. The same type error happens ifint
is swapped forreal
, but swapping it forstring
avoids it:Casting to a non-pair-y type seems to behave differently to casting to a pair-y type:
f((string)1)
here does compilef((int)1)
for theint
versions does not compile, likewisef((real)1)
for thereal
versionThis happens on both the web version (2.86-7) and the latest version available on my repo (2.70)