Improved error message for accessing local variables before they are assigned

If someone tries to access a global variable (like a function object) in a function and later in the function assignes a value to an identifier with the same name, they might be confused when they get the error "variable not defined", when it was in fact defined twice. This commit changes the message to a more descriptive "local identifier "variable" referenced before assignment"

This is a response to #4834

I didn't quite understand setting where this error is raised, so I hope that someone will see if the same function is used for other purposes, where this change of wording might be misleading.