Properly handle invalid arguments in builtins

Fixes #1522