Re: plpgsql unreachable code (was BUG #1329: Bug in IF-ELSEIF-ELSE construct)

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Neil Conway <neilc@samurai.com>
Cc: PostgreSQL-patches <pgsql-patches@postgresql.org>, Rico Wind <rw@rico-wind.dk>, pgsql-bugs@postgresql.org
Date: 2004-11-27T17:43:53Z
Lists: pgsql-bugs
Neil Conway <neilc@samurai.com> writes:
>> (BTW, another thing this example exposes is that we don't issue warnings 
>> about trivially-dead-code, such as statements in a basic block that 
>> follow a RETURN. This would probably be also worth doing.)

> Attached is a patch that implements this. Specifically, if there are any 
> statements in the same block that follow a RETURN, EXIT (without 
> condition) or RAISE EXCEPTION statement, we issue a warning at CREATE 
> FUNCTION time:

I think it would be sufficient to warn about the statement immediately
following the RETURN, EXIT, etc.  The way you've got it could easily
bury the user in a mass of warning messages that don't really convey
any extra information.

You could possibly give two alternative messages:
	WARNING:  assignment is unreachable, due to exit near line 6
	WARNING:  assignment and following statement(s) are unreachable, due to exit near line 6
but I'm not sure that's worth the trouble.

Also, you must use ereport not elog for any user-facing error messages,
because elog messages aren't candidates for translation.

			regards, tom lane