Here's something I run into on a regular basis; consider the following code:
funcdef fd@ fd();
fd@ f() {
return true ? f : f;
}
This will not compile because it "can't implicitly convert from '$func@' to 'fd@'". As far as I can tell, there's in fact no way to use the result of a conditional expression whose result is an unspecified function handle. I attempted conversions and casts but they're unsurprisingly ineffective. I also tried calling a result but that is similarly impossible:
void f() {
(true ? f : f)();
}
This code fails with "No matching signatures to '$func::opCall()'". To my surprise, the conditional operator also doesn't differentiate between functions with completely varying signatures, i.e. the following code actually compiles:
int g(int) {
return 0;
}
void f() {
true ? f : g;
}
Not that the result is possible to use in any way. Another interesting fact is that whereas code
funcdef fd@ fd();
fd@ f() {
fd@ h = f;
return true ? h : f;
}
compiles, very similar code
funcdef fd@ fd();
fd@ f() {
fd@ h = f;
return true ? f : h;
}
does not. It appears to me that making all of this work as expected would require major changes to the engine, so as a more viable solution I'd suggest enabling the syntax:
funcdef fd@ fd();
fd@ f() {
return true ? fd(f) : fd(f);
}
i.e. explicit conversion to a specific function handle.