+ if (inputElementBaseType == MONEYOID ||
+ targetElementBaseType == MONEYOID ||
+ (inputElementBaseType == CIRCLEOID &&
+ targetElementBaseType == POLYGONOID))
+ {
+ errorsafe_coercion = false;
+ }

What if we just reject cast functions with a non-null prosqlbody?
 

Given the interaction with array and domain coercion, we need to think more
about error-safe type casts for user-defined range, multirange, and composite
types.  For now, we should disallow error-safe casting for these types.

I agree. It's far better to get this working for the majority of cases, and we can chip away at more obscure types later. There will *always* be user defined types that we cannot account for.