Fix #599: Make anonymous function optimization fail rather than crash