Delphi's latest compiler provides a hint in these cases:
var
x: Int32;
begin
try
x := 0;
x := 1;
writeln(x);
end.
[dcc32 Hint] Project1.dpr(14): H2077 Value assigned to 'x' never used
(Line 14 is the one assigning zero.)
---- On Thu, 09 Feb 2017 04:30:06 -0500 Tim Ward [email protected]
[firebird-support] <[email protected]> wrote ----
It' the equivalent in a conventional programming language of saying:
x = a;
x = b;
where the compiler is expected to know that neither a not the first assignment
have any side effects other than the assignment (and where the expression b
doesn't depend on the value of x)(and where x isn't volatile, ect ect).
A compiler *could* detect and warn about such things (ie it's not forbidden by
the laws of mathematics) but I don't think I know of any that do. And as there
are good reasons for deliberately wanting to do the above it could only be a
warning, not an error.