Switch evaluates all of the expressions, even though it returns only one of them. For this reason, you should watch for undesirable side effects. For example, if the evaluation of any expression results in a division by zero error, an error occurs.
It has to do with your data typing in the Function. per the MS Help (above) 'switch' is evaling ALL expressions for each record. The Nulls are throughing an error in your function.
Ans. modify your function to process each record and check whether its null or a date, then just call the function and don't bother with switch.
OR use the IIF function insted of Switch:
This worked flawlessly with your test() funcation as is.
SELECT tableTest.id, tableTest.maturity, IIF([maturity] Is Null,0,test([maturity])) AS Expr1