Fixes optional argument check

Might fix #6386 

I played around with compressing the if statement down to one line with a ternary operator, but it was much more readable this way.