[SPARK-2549] Functions defined inside of other functions trigger failures