You aren't doing anything wrong, this is a limitation of the compiler that compiles Curv code into GPU instructions.
The problem is that on the GPU (I am compiling into GLSL), functions are not values. Unlike C, there is no concept of a function pointer.
box.mitred and box are both functions.
`if (boxMitred) box.mitred else box` is an expression that computes a function value *at GPU run time*, conditional on boxMitred. In C, this expression would return a function pointer. But there are no function pointers on the GPU, so my poor, stupid compiler just doesn't know what to do with this.
In the second example, boxMitred is a compile time constant, so the result of the expression is a function that is known at GPU compile time, so it works. The compiler uses partial evaluation to resolve as many subexpressions as possible at GPU compile time.
So it's a compiler bug, that I plan to have fixed for the Curv 1.0 release. The compiler will need an improved ability to perform static analysis and transform code from one form to another.
I will experiment with workarounds and post something more later.
Doug Moen.